Print all Documents in SharePoint Library PowerShell

I put together the following script to help out someone on the internets, the requirement was to print all documents in a SP library. This PowerShell iterates through a library (folders included), downloads a local copy, then prints to the default printer on the machine it is executed on.

Swap $destination, $webURL and $listUrl parameters as needed.

Fun for the whole family and keeping our paper mill workers gainfully employed!

 

######################## Start Variables ########################
$destination = "C:"
$webUrl = "https://mysharepoint/sites/sitename/"
$listUrl = "https://mysharepoint/sites/sitename/Shared%20Documents/"
##############################################################
$web = Get-SPWeb -Identity $webUrl
$list = $web.GetList($listUrl)

function ProcessFolder {
    param($folderUrl)
    $folder = $web.GetFolder($folderUrl)
    foreach ($file in $folder.Files) {
        #Ensure destination directory
        $destinationfolder = $destination + "/" + $folder.Url 
        if (!(Test-Path -path $destinationfolder))
        {
            $dest = New-Item $destinationfolder -type directory 
        }
        #Download file
        $binary = $file.OpenBinary()
        $stream = New-Object System.IO.FileStream($destinationfolder + "/" + $file.Name), Create
        $writer = New-Object System.IO.BinaryWriter($stream)
        $writer.write($binary)
        $writer.Close()
		Start-Process -FilePath ($destinationfolder + "/" + $file.Name) -Verb Print
        }
}

#Download root files
ProcessFolder($list.RootFolder.Url)
#Download files in folders
foreach ($folder in $list.Folders) {
    ProcessFolder($folder.Url)
}

Leave a Reply

I've been low-key stressed about how to view the many email inboxes I have in Outlook in one view without having to scroll and hunt for new messages.

The 'macro' method in this video works great.

View Multiple Inboxes at Once in Outlook 365 https://youtu.be/NpFSsovHgVo via @YouTube

We help Department of Defense clients realize benefits such as faster decision making, total traceability, and automated updates by identifying targeted goals and putting an emphasis on a culture of adoption through buy-in by individual team members.

https://bit.ly/3IRc68a

How to: Create a report quickly from a #SharePoint list or library in the #PowerBI service
📈📉📊📈📉📊
https://bit.ly/3vbKfMD
#Microsoft365

Leverage Microsoft Project for the web with the Project Accelerator https://youtu.be/Hxr8dncHmT8 via @YouTube

Load More...