SOLVED

Chicken - egg: How to add a Site Collection admin via PowerShell if you are SPO Admin/Global Admin

Steel Contributor

Hi everyone,

maybe i am doing something wrong but after trying various commands - i just don't get it.

As a former SP2013 Admin i want to execute a PowerShell that adds certain users or groups to SharePoint Groups.

Script is written but i come across a problem that i had earlier and i decided to fix it this time ;)

In the old world i took the farm admin and shoot.... done.

New world (i am global admin) i do not have the permission to add a user to a group because i am no site colladmin or owner.

So do i need to add myself to the sitecollection via set-sposite and then perform the steps? And if yes. Is there a PNP equivalent? (tried but gave me 401)

 

Who should be the Site Coll Admin for most of the sites?

 

Best regards

Stephan

1 Reply
best response confirmed by StephanGee (Steel Contributor)
Solution
I ended up adding a group to all site collections as admin.
Script i wrote:
ry {

# Connect to SPO
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
connect-SPOService -Url https://tenant365-admin.sharepoint.com


#defs
$sites = @()
$Ownergroup = "ACL_ABBR-SPO_ITAdmins"

function BulkADGrouptoSPOGroup {

#$sites = Import-Csv -Path "$PSScriptRoot\ADD_Bulk_Permissions.csv" -Delimiter ";" -Encoding "UTF8"
$sites = Get-SPOSite -Limit All | Where-Object Url -like "*ABBR-INTRANET*"
$sites += Get-SPOSite -Limit All | Where-Object Url -like "*ABBR2-INTRANET*"
Write-Host "Starting adding AD Group to SPO Admins..." -ForegroundColor yellow

foreach ($site in $sites) {
Write-Host "Add $ownergroup to $site.url with role Admin" -ForegroundColor Yellow
Set-SPOSite -Identity $site.url -Owner $ownergroup
Start-Sleep -Seconds 2
}


}
}

catch {

}
1 best response

Accepted Solutions
best response confirmed by StephanGee (Steel Contributor)
Solution
I ended up adding a group to all site collections as admin.
Script i wrote:
ry {

# Connect to SPO
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
connect-SPOService -Url https://tenant365-admin.sharepoint.com


#defs
$sites = @()
$Ownergroup = "ACL_ABBR-SPO_ITAdmins"

function BulkADGrouptoSPOGroup {

#$sites = Import-Csv -Path "$PSScriptRoot\ADD_Bulk_Permissions.csv" -Delimiter ";" -Encoding "UTF8"
$sites = Get-SPOSite -Limit All | Where-Object Url -like "*ABBR-INTRANET*"
$sites += Get-SPOSite -Limit All | Where-Object Url -like "*ABBR2-INTRANET*"
Write-Host "Starting adding AD Group to SPO Admins..." -ForegroundColor yellow

foreach ($site in $sites) {
Write-Host "Add $ownergroup to $site.url with role Admin" -ForegroundColor Yellow
Set-SPOSite -Identity $site.url -Owner $ownergroup
Start-Sleep -Seconds 2
}


}
}

catch {

}

View solution in original post