Thursday, July 4, 2019

Powershell to Download Pages from SharePoint Pages Library

Powershell to Download Pages from SharePoint Pages Library - SharePoint Onprem.


Run that below Powershell in SharePoint Management studio on SP Onprem server(SP 2010/2013)

Note -
Change the variable and run the powershell to get the output.

--------------------------------------------------------------------------------------------------------------------



$destination ="\\hamal\sOffice365Mig$\Mig\Download_Pages\RL_strategy"
$webUrl ="http://sharepoint.com"
$listUrl ="http://sharepoint.com/circles/RL%20Strategy%20and%20Plans/Forms/AllItems.aspx"
##############################################################


$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()
        }
}

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

No comments:

Post a Comment