0

I would like to remove user x from all site collections and replace with user y using powershell. Does anyone have a script that works? Google hasn't been helpful this time :-(

3
  • is it primary or secondary site collection admin? Commented Nov 22, 2016 at 16:29
  • I think Primary Commented Nov 22, 2016 at 16:30
  • then it is easy for on prem Commented Nov 22, 2016 at 16:35

2 Answers 2

1

It would be a 2 step process, this is for SPO, but could be adapted for on prem easily enough.

$sites = get-sposite -limit All #process sites foreach($site in $sites){ Set-SPOUser -LoginName "[email protected]" -IsSiteCollectionAdmin $false -Site $site.Url Set-SPOUser -LoginName "[email protected]" -IsSiteCollectionAdmin $true -Site $site.Url } 

For on prem, it would look something like (not tested, no on prem instance to verify against)

$sites = get-spsite -limit All #process sites foreach($site in $sites){ Set-SPUser -Identity "domain\user1" -IsSiteCollectionAdmin:$false -Web $site.RootWeb.Url # colon is necessary Set-SPUser -Identity "domain\user2" -IsSiteCollectionAdmin:$true -Web $site.RootWeb.Url } 
0

You just need to set the new primary admin, it will remove the old.

 Write-Host -Foregroundcolor green "- Changing the site collection administrators" $site = Get-SPSite | ?{$_.Url -like "*sites/tempSite*"} If ($site -ne $null) { Set-SPSite -Identity $site.Url -OwnerAlias "DOMAIN\farmacc" -SecondaryOwnerAlias "DOMAIN\svcacc" Write-Host -Foregroundcolor white "- Site Collection Administrators for '$site' is changed." } 

I haven't tested but it will work. Changing Site Collection Administrators using PowerShell

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.