Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function FolderFromSharepoint(){
- [CmdletBinding()]
- param(
- [Parameter(Position=0,mandatory=$true)]
- [string]$spVer,
- [string]$url,
- [string]$driveLtr,
- [string]$localPath)
- BEGIN{
- cls
- $driveLtr = "Z"
- $localPath = "c:/temp/"
- #Create PSDrive
- Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/test -UseWebLogin -CreateDrive -DriveName $driveLtr
- #Get All Items in a Folder
- #$siteItems = (gci ($driveLtr + ':'))
- #Get All Items in a Folder
- $siteItems = (gci ($driveLtr + ':') -Recurse) | ?{$_.GetType().Name -eq 'Folder'} | Where {$_.Name -eq 'Shared Documents'}
- #Separate Folders and Files
- #$folders = $siteItems | ?{$_.GetType().Name -eq 'SubFolder'} | Where {$_.Name -eq "General"}
- #$files = $siteItems | ?{$_.GetType().Name -eq 'File'}
- }
- PROCESS{
- #Create Folder Start
- #$folders | ForEach-Object { New-Item -ItemType directory -path ($localPath + $_.ServerRelativeUrl) -force }
- #Copy Files Start
- #$files | ForEach-Object { Copy-Item ('Z:' + $_.ServerRelativeUrl) -Destination ($localPath + ($_.ServerRelativeUrl -replace $_.Name)) }
- #Create Root Directory
- $destFolder = New-Item -ItemType directory -path ($localPath + (Get-PSDrive $driveLtr).CurrentLocation) -force # | Out-Null
- $siteItems | ? { $_.Name -eq 'General' } | % {
- $folder_item = $_
- #Get Full Path To Desired Folder Location
- write-host "Copying: $(($folder_item.PSParentPath -split '::')[1] + "\" + $folder_item.Name) to $(($localPath + (Get-PSDrive $driveLtr).CurrentLocation))"
- Copy-Item ((Get-PSDrive $driveLtr).Name + ":\" + $folder_item.ServerRelativeUrl ) -Destination ($localPath + (Get-PSDrive $driveLtr).CurrentLocation) -recurse -container
- }
- }
- END{
- #Remove PSDrive
- Get-PSDrive $driveLtr | Remove-PSDrive
- }
- }
- FolderFromSharepoint -spVer 2016 -url 'https://sharepoint.contosos.com/{site}' -driveLtr $driveLtr -localPath $localPath
Add Comment
Please, Sign In to add comment