Getting and changing site admins in SharePoint Server with PowerShell

In the previous post we discussed SharePoint Online cloud service. Now, let’s talk about SharePoint farm deployed on premises.

We can specify Primary and Secondary site collection administrators in the SharePoint Central Administration portal by clicking on Application Management and then on Change site collection administrators in the Site Collections section.

Primary and secondary administrators are those who, among other things, receive e-mail notifications about various SharePoint event, like when a site collection reaches its storage limit.

Also, you can specify list of other administrators in the Site Settings. To do this, on the site collection click the cog at the upper right part of the page and then click Site Settings. If there is no such a setting in the menu, click on the Site information and then on the View all site settings. Finally, click on the Site collection administrators in the Users and Permissions section.

Now, let’s do it with PowerShell.

Primary and Secondary administrator

The Primary site collections administrator is specified in the Owner property, and the Secondary administrator is in the SecondaryContact property of the Microsoft.SharePoint.SPSite object, which is returned by the Get-SPSite cmdlet.

Get-SPSite -Identity http://ServerName/SitePath | Select-Object -Property Owner, SecondaryContact

The values of both properties are the Microsoft.SharePoint.SPUser objects, so if you need a more detailed information about these administrators, you can use the following commands.

Get-SPSite -Identity http://ServerName/SitePath | Select-Object -ExpandProperty Owner
Get-SPSite -Identity http://ServerName/SitePath | Select-Object -ExpandProperty SecondaryContact

On the other hand, if all you need is a username of the primary administrator, you can get the value of the OwnerLoginName property of the Microsoft.SharePoint.SPSite object.

Get-SPSite -Identity http://ServerName/SitePath | Select-Object -Property OwnerLoginName

You can change the Primary and Secondary administrators using Set-SPSite cmdlet and its -OwnerAlias and -SecondaryOwnerAlias parameters, respectively.

Set-SPSite -Identity http://ServerName/SitePath -OwnerAlias -SecondaryOwnerAlias


Get site collection administrators list

You can get the list of administrators using the same Get-SPSite cmdlet. To do this, you should get the value of the RootWeb property of the Microsoft.SharePoint.SPSite object, and then get the SiteAdministrators property of the acquired object.

For example.

$site = Get-SPSite -Identity http://ServerName/SitePath

Need to say, that this list contains all site collection administrators, including the Primary and Secondary administrators.

Also you can get site collection administrators list using the Get-SPUser cmdlet.

Get-SPUser -Web http://ServerName/SitePath | Where-Object -Property IsSiteAdmin

Add site collection administrators

In order to specify a user as a site collection administrator, you can use Set-SPUser cmdlet and its -IsSiteCollectionAdmin parameter. Since it is a switch parameter, no value required.

Set-SPUser -Web http://ServerName/SitePath -Identity NewAdminIdentity -IsSiteCollectionAdmin

For example, the command might look like this.

Set-SPUser -Web http://sharepointserver/sites/site -Identity 'i:0#.w|domain\newadmin' -IsSiteCollectionAdmin

Remove site collection administrators

Removing a user from administrators occurs in a similar way. However, since, as we mentioned before, the -IsSiteCollectionAdmin is a switch parameter, in this case we should specify it as follows: -IsSiteCollectionAdmin:$false.

Set-SPUser -Web http://ServerName/SitePath -Identity NewAdminIdentity -IsSiteCollectionAdmin:$false



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s