powershell-scripts/m365/migration/Grant-SPOPersonalSiteCollectionAdmin.ps1
2024-08-22 10:33:51 -04:00

22 lines
758 B
PowerShell

#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
}