Share via


SharePoint 2010: Export Site Collection Administrators to a List

Scenario

Someone asks how they can use an OOTB (out of the box) webpart to show a list of site collection administrators on a site page. 

Solution

One way to do this is to use PowerShell to export a list of the site collection administrators into a SharePoint list, then display the list items (administrators) with a content query webpart. 

The first thing we need to do is create a SharePoint list and add columns need to display the site collection and administrator. Create a column for the site URL and one for the administrators name.

 

http://3.bp.blogspot.com/-_A5HHEUhn00/UhTlwR5SF1I/AAAAAAAAACI/pZR0mScQR2E/s320/Image1.png

 

Now for the PowerShell Script.

Note: The highlighted parts would need to change to match your environment in red.

#Add the SharePoint PowerShell SnapIn             
Add-PSSnapIn Microsoft.SharePoint.PowerShell              
#Specify the Site Collection which holds the list where we want to import the administrators             
$liburl = "[Site Collection URL]"              
#Specify the name of the list             
$listname = "Admins"              
#Load the SharePoint Site             
$web = get-spweb $liburl              
#Load the SharePoint List             
$list = $web.lists[$listname]              
#Return our list of Sites and Site owners and store in a variable             
$import = get-spsiteadministration -limit all| select -property url, ownerloginname              
#The foreach loop will take each of the entries from our previous query and write them to the list             
foreach($i in $import)              
{              
 #This line adds the items specifed to our list             
 $newitem = $list.items.add()              
 #Here we specify that the list column "Column 1" should contain the site url             
 $newitem["URL"] = $i.url              
 #Here we specify that the list column "Column 2" should contain the site owner             
 $newitem["Admin"] = $i.ownerloginname               
 #This line sends the update to the list             
 $newitem.update()              
}

Once we have run this PowershellScript our list will be populated with our site administrators, and we can use a Content Query Webpart to display the site collection administrators and site url on a SharePoint site page.
 

Other languages

This article is also available in the following languages: