Download document library files from SharePoint Online to your local by PowerShell command

2023/01/01

How to download library document from sharepoint online by powershell script.

Web browser download function in sharepoint do fails to compress files and not stable to bulk download.

Powershell script will help you to get sharepoint document library by each single file in target folder.  

How to download a file from SharePoint Online using PowerShell? Well, Here is the PowerShell script to download a file from SharePoint Online!

Prerequisite

-Windows PC, to run powershell as adminitrator

-Sharepoint account , access to target sharepoint library


STEP 1 Start Powershell

To access to sharepoint by powershell, you need module for command library to control sharepoint.

On your local computer, start powershell  as Administrator. 



STEP 2 Install PnP PowerShell

Install "PnP PowerShell" to your local computer in powershell command.

You can see details in overview for PnP PowerShell in Microsoft site.

Command
Install-Module -Name "PnP.PowerShell"

If confirmation ask you to install module, please continue with "A".




STEP 3 Prepare Local Folder

Prepare Local Folder on your computer.




STEP 4  Download script and update parameters

Please download following command lines and update 3 parameters

your sharepoint site URL, target sharepoint path, your local computer path (red line in below command)

STEP 5 Run script and logon

Download Here

after download script, you should update 3 parameters.

Your Sharepoint Site

$SiteURL = "https://<yoursharepointsite>/sites/<yoursitename>"

Your Local Path

$DownloadPath ="D:\<yourlocal>\<yourlocalsub>"
 

Your Sharepoint Authentication Type

Using non-MFA, login with password
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential) 
or
Using MFA 
Connect-PnPOnline -Url $SiteURL -UseWebLogin


after update parameters. copy and paste your script with updated parameter on your powershell screen.

on "Connect-PnPOnline -Url $SiteURL -Interactive" command, logon screen to sharepoint is shown by pop-up.



after logon successfully, file download from sharepoint to your local will start in your powershell.


STEP 6  Check status 

Command will start to reply download status.

you can check downloaded files in local computer.



Appendix  get command log with text file 

You can get command log with follwong command in powershell. 

If you try to download a large document folder , sometime the download command   raise error.

You should capture all log file durling download operarion, and retry to download the failed file.

Command
Start-Transcript

start transcript command will create log files in your local document folder automatically,


Command
StopTranscript
stop transcript or close your powershell screen close log files automatically



このブログを検索

ブログ アーカイブ

Powered by Blogger.

QooQ