List OneDrive Sites and Admins

Run this to export all OneDrive URLs with site admins (temporarily grants access):

$username = "admin@domain.com"
$Sites = Get-SPOSite -IncludePersonalSite $true -Limit all -Filter "Url -like '-my.sharepoint.com/personal/'"
foreach ($Site in $sites) {
  $URL = $Site.URL
  Set-SPOUser -Site $URL -LoginName $username -IsSiteCollectionAdmin $true
  Get-SPOUser -Site $URL -Limit all | Where {$_.IsSiteAdmin -eq $True} | Select-Object @{Label="Site";Expression={"$URL"}},@{Label="AdminName";Expression={$_.DisplayName}} | export-csv C:\OneDriveAdmins.csv -NoTypeInformation -append -encoding ASCII
  Set-SPOUser -Site $URL -LoginName $username -IsSiteCollectionAdmin $false
}

Leave a Reply