How to Download a File from SharePoint Library using PowerShell?

Requirement: Download a File from SharePoint Document Library using PowerShell

How to Download a File from a Library in SharePoint?

Users can download copies of files from the SharePoint libraries to another location, such as the local computer or an accessible network file share. To download a copy of a file from a document library, do the following:

  • Go to your SharePoint document library and select the file to download. 
  • From the “Files” tab, click on the “Download a Copy” button from the ribbon. 
    download sharepoint file using powershell
  • This opens the “Save as” pop-up. Click “Save as” and select a location where the document copy will be saved. Specify the name for the document and click on “Save”.

You’ll see the message “download has completed” at the bottom of the browser window. You can also use “Download a Copy” from the document’s context menu. Just click the ellipsis icon on the pop-up window and choose “Download a Copy”.

Download a File from SharePoint using PowerShell

If you are looking for a way to automate the process of downloading files from SharePoint, PowerShell is the perfect solution. This guide will show you how to use PowerShell to download SharePoint files quickly and easily.

Here is how to download SharePoint File using PowerShell:

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Set Parameters
$WebURL = "https://opera.crescent.com/sites/template/"
$FileRelativedURL = "/Sites/template/Shared Documents/ASI-LOG.docx"
$LocalFolderPath = "C:\Template"

Try {
    #Ensure the destination local folder exists! 
    if (!(Test-Path -path $LocalFolderPath))
    {    
         #If it doesn't exists, Create
         $LocalFolder = New-Item $LocalFolderPath -type directory 
    }

    #Get the Fie
    $Web = Get-SPWeb $WebURL
    $File = $Web.GetFile($FileRelativedURL)

    #Download the file
    $Data = $File.OpenBinary()
    $FilePath = Join-Path $LocalFolderPath $File.Name
    [System.IO.File]::WriteAllBytes($FilePath, $Data)

    Write-host -f Green "File downloaded Successfully!"
}
Catch {
Write-host -f Red "Error:" $_.Exception.Message
}

To download all files from a SharePoint document library using PowerShell, use: Download All Files from SharePoint Document Library using PowerShell

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply