Our great sponsors
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
# Use system-assigned managed identity # https://mmsharepoint.wordpress.com/2023/05/04/authentication-in-azure-automation-with-managed-identity-on-sharepoint-and-microsoft-graph/ # https://pnp.github.io/powershell/articles/azureautomationrunbook.html # Connect to multiple sites # https://github.com/pnp/powershell/issues/1748 # https://robdy.io/multiple-pnp-connections/ # Prod $SourceStr = Get-AutomationVariable -Name 'SharePointSourceFolders' $Target = Get-AutomationVariable -Name 'SharePointTargetFolder' #$SourceList = $SourceStr.Split([System.Environment]::NewLine,[System.StringSplitOptions]::RemoveEmptyEntries) $SourceList = $SourceStr.Split("\n") # Commmon Foreach($Source in $SourceList){ Try{ Write-Output "Source Folder: $Source" #Dev #$SourceSiteConnection = Connect-PnPOnline -Url $SourceSiteURL -Interactive -ReturnConnection #Prod $SourceSiteConnection = Connect-PnPOnline -Url $SourceSiteURL -ManagedIdentity -ReturnConnection #Get the total Size of the folder - with versions $SourceFolder = Get-PnPFolder -Url $Source -Includes ListItemAllFields -Connection $SourceSiteConnection $SourceFolderSize = $([Math]::Round(($SourceFolder.ListItemAllFields.FieldValues.SMTotalSize.LookupId/1KB),2)) Write-Output "Source Folder Size: $Source : $SourceFolderSize" $job = Move-PnPFile -SourceUrl $Source -TargetUrl $Target -NoWait -Overwrite -AllowSchemaMismatch -AllowSmallerVersionLimitOnDestination -Force -Connection $SourceSiteConnection $jobStatus = Receive-PnPCopyMoveJobStatus -Job $job -Wait -Connection $SourceSiteConnection if($jobStatus.JobState -eq 0){ Write-Output "Job finished" $jobStatus.JobState $jobStatus.Logs $SourceFolder = Get-PnPFolder -Url $Source -Includes ListItemAllFields -Connection $SourceSiteConnection -ErrorAction SilentlyContinue if($SourceFolder){ Write-Output "Second Try because folder: $SourceFolder.Name remains" $SourceFolderSize = $([Math]::Round(($SourceFolder.ListItemAllFields.FieldValues.SMTotalSize.LookupId/1KB),2)) Write-Output "Second Try Source Folder Size: $Source : $SourceFolderSize" $job = Move-PnPFile -SourceUrl $Source -TargetUrl $Target -NoWait -Overwrite -AllowSchemaMismatch -AllowSmallerVersionLimitOnDestination -Force -Connection $SourceSiteConnection $jobStatus = Receive-PnPCopyMoveJobStatus -Job $job -Wait -Connection $SourceSiteConnection if($jobStatus.JobState -eq 0){ Write-Output "Second TryJob finished" $jobStatus.JobState $jobStatus.Logs } else{ Write-Error "Second Try Status: $jobStatus" } } } else{ Write-Error "$jobStatus" } } catch { Write-Error "An error occurred: ${Source}: $_" } # Dispose the connnection variables $SourceSiteConnection = $null Write-Output "Sleep for 2 seconds" Start-Sleep -Milliseconds 2000 }
Official doc on runbook limitations: https://github.com/MicrosoftDocs/azure-docs/blob/main/includes/azure-automation-service-limits.md
Related posts
- “In a Month of Lunches”-Like for Graph for Powershell?
- Using Batch with Sharepoint Powershell
- Access to Another User's OneDrive (GraphAPI and Microsoft.Graph issues)
- My boss won’t allow linking our sharepoint site onto file explorer and it’s driving our users insane.
- SharePoint Website in andere Umgebungen verschieben.