Powershell script to get site Title, Site Owner, Site user count and usage

Powershell script to get site Title, Site Owner, Site user count and usage

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
$wburl = Read-Host "Enter Web application URL "
$webApp = Get-SPWebApplication $wburl
$outputPath =Read-Host "Enter path to save results "
Add-Content -Path $outputPath -Value "Site Title,Site URL, Site Owner, UserCount,Usage in MB"
foreach ($SiteCollection in $webApp.Sites)
{
$url = $SiteCollection.Url
$webs = Get-SPWeb $URL
[boolean] $WriteToFile = $true
$weburl = $SiteCollection.OpenWeb()
$siteowner = ""
foreach ($siteAdmin in $weburl.SiteAdministrators)
{
$siteowner = $siteAdmin.LoginName + "|" + $siteowner
}
foreach($web in $webs)
{
#Grab all users in the site collections
$siteUserCnt = $web.AllUsers.Count
$Siteurl = $web.Url
$siteTitle = $web.Title
$site = Get-SPSite  $Siteurl

$siteusage = $site.Usage.Storage/1MB

Add-Content -Path $outputPath -Value "$siteTitle,$Siteurl,$siteowner,$siteUserCnt,$siteusage"
$web.Dispose()
}
}
Advertisements

One thought on “Powershell script to get site Title, Site Owner, Site user count and usage

  1. This will give you a list of Site Administrators, but not necessarily Site Owners. For that you need to loop through the SPWeb.AssociatedOwnerGroup property and grab the users from there.

    Also, you should call Dispose() on your $weburl and potentially $webs variables (both are SPWeb objects).

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s