Powershell script to Download All Contents ( Folder and Files ) from Sharepoint and Local to SharePoint

Karl 20 Reputation points
2024-05-30T06:10:30.32+00:00

Hi There,

Good Day.

Would like to seek your assistance on how we able to transfer/download Folder with files and sub-folder, files to Local Drive from Sharepoint and Local to SharePoint.

Greatly appreciate your feedback. Thank You.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,011 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,219 questions
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 32,556 Reputation points Microsoft Vendor
    2024-05-31T02:54:32.3+00:00

    Hi @Karl,

    You could refer to following script to download file

    $LocalFolder = 'C:\Reports'
    
    $UrlSharepoint = 'https://zietza.sharepoint.com'
    $UrlSite = '/sites/tm_Finance'
    $LibraryFolder = '/Shared Documents/Budgets'
    
    # Connect to Sharepoint and save the connection
    $Connection = Connect-PnPOnline -Url "${UrlSharepoint}${UrlSite}" `
                        -Credential $Credential `
                        -ReturnConnection `
                        -ErrorAction Stop
    try {
        Get-PnPFolderItem -FolderSiteRelativeUrl $LibraryFolder `
                          -Connection $Connection `
                          -ItemType File `
                          -Recursive | 
            Where-Object {$_.ServerRelativeUrl -like "*" } | 
            Select-Object name, @{
                                    name='SiteRelativePath'
                                    expr={$_.ServerRelativeUrl.Substring($UrlSite.Length)} 
                                } | 
            ForEach-Object {
                Get-PnPFile -Url $_.SiteRelativePath `
                            -AsFile `
                            -Path $LocalFolder `
                            -Filename $_.name `
                            -Connection $Connection
            }
    }
    finally {
        # Make sure to disconnect
        Disconnect-PnpOnline -Connection $Connection
    }
    
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful