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{
- #Create PSDrive
- Connect-PnPOnline -Url https://TEST.sharepoint.com/sites/TEST -UseWebLogin -CreateDrive -DriveName $driveLtr
- #Get All Items in a Folder
- #$siteItems = (gci ($driveLtr + ':'))
- $siteItems = (gci ($driveLtr + ':')) | ?{$_.GetType().Name -eq 'Folder'} | Where {$_.Name -eq "Shared Documents"}
- }
- PROCESS{
- #Create Root Directory
- New-Item -ItemType directory -path ($localPath + (Get-PSDrive $driveLtr).CurrentLocation) -force | Out-Null
- $siteItems | ForEach-Object {
- Copy-Item ((Get-PSDrive $driveLtr).Name + ":\" + (Get-PSDrive $driveLtr).CurrentLocation + "\" + $_.Name) -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 'Z' -localPath 'C:/temp'
Add Comment
Please, Sign In to add comment