Guest User

Folder

a guest
May 25th, 2020
64
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function FolderFromSharepoint(){
  2.  
  3. [CmdletBinding()]
  4. param(
  5. [Parameter(Position=0,mandatory=$true)]
  6. [string]$spVer,
  7. [string]$url,
  8. [string]$driveLtr,
  9. [string]$localPath)
  10.  
  11. BEGIN{
  12.  
  13.  
  14. #Create PSDrive
  15. Connect-PnPOnline -Url https://TEST.sharepoint.com/sites/TEST -UseWebLogin -CreateDrive -DriveName $driveLtr
  16.  
  17. #Get All Items in a Folder
  18.  
  19. #$siteItems = (gci ($driveLtr + ':'))
  20. $siteItems = (gci ($driveLtr + ':')) | ?{$_.GetType().Name -eq 'Folder'} | Where {$_.Name -eq "Shared Documents"}
  21.  
  22.  
  23. }
  24. PROCESS{
  25.  
  26. #Create Root Directory
  27. New-Item -ItemType directory -path ($localPath + (Get-PSDrive $driveLtr).CurrentLocation) -force | Out-Null
  28.  
  29. $siteItems | ForEach-Object {
  30. Copy-Item ((Get-PSDrive $driveLtr).Name + ":\" + (Get-PSDrive $driveLtr).CurrentLocation + "\" + $_.Name) -Destination ($localPath + (Get-PSDrive $driveLtr).CurrentLocation) -recurse -container
  31. }
  32.  
  33. }
  34. END{
  35. #Remove PSDrive
  36. Get-PSDrive $driveLtr | Remove-PSDrive
  37. }
  38. }
  39.  
  40. FolderFromSharepoint -spVer 2016 -url 'https://sharepoint.contosos.com/{site}' -driveLtr 'Z' -localPath 'C:/temp'
RAW Paste Data