This simple script lets you set an admin for multiple sites listed in a CSV file. It is helpful for when you want to perform admin actions on multiple sites
$SPAdminURL = "https://contoso-admin.sharepoint.com"
Connect-SPOService -Url $SPAdminURL
#$siteInfo = Get-SPOSite -Limit ALL |Select GroupId, URL
$siteInfo = Import-CSV C:\SWSetup\SharepointSites.csv
$AcctName = "username@contoso.com"
foreach ($s in $siteInfo)
{
Set-SPOUser -Site $s.URL -IsSiteCollectionAdmin $true -LoginName $AcctName
}
Connect-SPOService -Url $SPAdminURL
#$siteInfo = Get-SPOSite -Limit ALL |Select GroupId, URL
$siteInfo = Import-CSV C:\SWSetup\SharepointSites.csv
$AcctName = "username@contoso.com"
foreach ($s in $siteInfo)
{
Set-SPOUser -Site $s.URL -IsSiteCollectionAdmin $true -LoginName $AcctName
}
When you are finished, re-run the script, changing the $true to $false in Set-SPOUser.
If you have a O365 group to set as the owner, it's a little more complicated. Here is the script to do that:
$SPAdminURL = "https://contoso-admin.sharepoint.com"
Connect-SPOService -Url $SPAdminURL
Connect-PnPOnline -Url $SPAdminURL -Interactive
$siteInfo = Get-SPOSite -Limit ALL |Select GroupId, URL
#$siteInfo = Import-CSV C:\SWSetup\SharepointSites.csv
Function EnsureLoginName($userOrGroupName) {
$web = Get-PnPWeb
$userOrGroup = $web.EnsureUser($userOrGroupName)
$web.Context.Load($userOrGroup)
$web.Context.ExecuteQuery()
Return $userOrGroup.LoginName
}
$GroupName = EnsureLoginName "SharePoint Admins"
foreach ($s in $siteInfo)
{ Write-Host $s.Url
Set-SPOUser -Site $s.URL -IsSiteCollectionAdmin $true -LoginName $GroupName
}
Sources:
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.