0

How can I add a user as an all team sites (they are over 3000) Admin and an Owner list by PowerShell script? Is it also possible to add a user as an admin and an owner list automatically when creating a new team site?

1 Answer 1

0

You can add the user as site collection administrator in all site collection in a tenant using PowerShell command below:

$AdminURL = "https://tenant-admin.sharepoint.com/"
$AdminName = "[email protected]"
$NewUser = "[email protected]"

#User Names Password to connect 
$Password = Read-host -assecurestring "Enter Password for $AdminName"
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName, $Password

#Connect to SharePoint Online
Connect-SPOService -url $AdminURL -credential $Credential

$Sites = Get-SPOSite -Limit ALL

Foreach ($Site in $Sites)
{
    Write-host "Adding Site Collection Admin for:"$Site.URL
    Set-SPOUser -site $Site -LoginName $NewUser -IsSiteCollectionAdmin $True
}

For automatically setting the users as admin when creating a new team site, I recommend you using Windows Task Scheduler to run the PowerShell script.

How To Automatically Run PowerShell Scripts at a Scheduled Time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.