-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdd-SPOSiteCollectionAdmin.ps1
More file actions
29 lines (28 loc) · 1.13 KB
/
Add-SPOSiteCollectionAdmin.ps1
File metadata and controls
29 lines (28 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import-module Microsoft.Online.SharePoint.PowerShell -ErrorAction Stop
$tenant = Read-Host -Prompt "Please provide tenant name/domain"
Connect-SPOService -url "https://$tenant-admin.sharepoint.com" -ErrorAction Stop
$scadmin = Read-Host -Prompt "Please provide Site Collection Administrator UPN e.g. alans@contoso.com to add to every site collection"
foreach ($site in Get-SPOSite -Limit All)
{
try {
Set-SPOUser -site $site -LoginName $scadmin -IsSiteCollectionAdmin $true
}
catch {
if ($Error[0].Exception -like "(503)")
{
{
# The remote server returned an error: (503) Server Unavailable.
Write-Output "Try again in 10s"
Start-Sleep -Seconds 10
Set-SPOUser -site $site -LoginName $scadmin -IsSiteCollectionAdmin $true
$error.Clear()
}
else {
Write-Output "Failed: $($Error[0])"
Write-Output "Try again"
Start-Sleep -Seconds 5
Set-SPOUser -site $site -LoginName $scadmin -IsSiteCollectionAdmin $true
}
}
}
}