#Requires -Modules Microsoft.Online.SharePoint.PowerShell # Set the SharePoint Admin page URL $AdminUrl = 'https://contoso-admin.sharepoint.com' # Set the migration account name $MigrationAccount = 'migration@contoso.com' # Check and connect to the SPOService if we're not already $SiteCheck = '' Try { $SiteCheck = Get-SPOSite $AdminUrl } Catch [System.InvalidOperationException] { Connect-SPOService -Url $AdminUrl } # Get SPO personal sites $PersonalSites = Get-SPOSite -IncludePersonalSite $true | Where-Object { $_.Url -like "*personal*" } foreach ($Site in $PersonalSites) { # Grant $MigrationAccount Site Collection Admin on each personal site Set-SPOUser -Site $Site.Url -LoginName $MigrationAccount -IsSiteCollectionAdmin $true }