PowerShell script to update all Site Collection Owners

Requirement

Update the site collection owners for all sites in your SharePoint farm. You normally wouldn’t do this too often, but this is helpful when you are doing things like migrations from old SharePoint installations.

Having a valid account with a working e-mail address is important especially when you use site collection quotas and warning e-mails. When a site reaches its warning limit, it sends an e-mail notification to the site collection owner and secondary owner. If your accounts do not have a valid e-mail address, you will not receive any notification.

Solution

I have written a simple PowerShell script to change the site collection owner and secondary owner for all sites in your farm. As always, use it in your test environment first and feel free to modify as you see fit.

 

# This powershell script sets the site collection owner and secondary owner on all site collections in the farm to the account you specify.
 
Add-PSSnapin Microsoft.SharePoint.PowerShell
 
$owner = Read-Host "Enter site collection owner username: "
$second = Read-Host "Enter site collection secondary owner username: "
 
$sites = Get-SPSite -Limit all
 
foreach ($site in $sites)
{
	Write-Host Setting $site.url owner to $owner and secondary owner to $second
	stsadm -o siteowner -url $site.url -ownerlogin $owner -secondarylogin $second
}
 
Write-Host "Done"
 
$site.dispose()

Tags: , ,

No comments yet.

Leave a Reply

%d bloggers like this: