How to grant access to "SharePoint Service Administrator" domain group using PowerShell in SP Online?
It doesn't have a email and i tried with Account ID and name, both didn't work.
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityHow to grant access to "SharePoint Service Administrator" domain group using PowerShell in SP Online?
It doesn't have a email and i tried with Account ID and name, both didn't work.
Use the script below to automatically add user in the domain group -
$AdminURL = "https://domain-admin.sharepoint.com/"
$AdminName = "user.domain.onmicrosoft.com"
$SiteCollURL = "https://domain.sharepoint.com/sites/example"
$SiteCollectionAdmin = "[email protected]"
$SecurePWD = ConvertTo-SecureString "Password" –asplaintext –force
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName, $SecurePWD
Connect-SPOService -url $AdminURL -credential $Credential
Set-SPOUser -site $SiteCollURL -LoginName $SiteCollectionAdmin -IsSiteCollectionAdmin $True
I was able to achieve it through PnP Powershell. Below is the PnP powershell script to update "SharePoint Service Administrator" as SCA for all site collections:
$credentials=Get-Credential
$URL="https://Company.sharepoint.com"
Connect-PnPOnline -Url $URL -Credentials $credentials
$siteColl=Get-PnPTenantSite
$loginName = "c:0t.c|tenant|ID Of SharePoint Service Administrator domain group in your tenant"
foreach($site in $siteColl)
{
write-host -ForegroundColor Green "Updating SCA for site: " $site.Url
Connect-PnPOnline -Url $site.Url -Credentials $credentials
$scaColl=Get-PnPSiteCollectionAdmin
foreach($sca in $scaColl)
{
Add-PnPSiteCollectionAdmin -owners $loginname
}
}