SharePoint: Planning for the Future - PowerShell Scripts

I recently presented a session on planning for the future with SharePoint, as promised to the attendees, below are two of the scripts that I used in my demonstrations to audit Content databases and Site Collections.

Content Database Inventory
This script outputs details of all Content Databases within a SharePoint farm to a CSV file, this includes the following information:

  • Name
  • SQL Server
  • Web Application
  • Current number of sites
  • Maximum number of sites allowed
  • Total size of the database (MB)

Prior to running the script please update highlighted with the location to store the output CSV file.

asnp *SharePoint* -ErrorAction SilentlyContinue
#Configure output location for CSV file
$Output = "D:\CDBInventory.csv"
#Create headings in the CSV file
$Headings = "Name","Server","Web App","No. of Sites","Max Site Count","Size (MB)",
$Headings -join "," | Out-File -Encoding default -FilePath $Output
#Loop through each Site Collection and output the required properties
Foreach ($CDB in (Get-SPContentDatabase))
{
$Info =
$CDB.Name,
$CDB.Server,
$CDB.WebApplication.Url,
$CDB.CurrentSiteCount,
$CDB.MaximumSiteCount,
($CDB.DiskSizeRequired /1MB),
$Info -join "," | Out-File -Encoding default -Append -FilePath $Output
}

Belowis an example of the CSV file created.

Site Collection Inventory

This script outputs details of all Site Collections within a SharePoint farm to a CSV file, this includes the following information:

  • URL
  • Owner
  • Content database the Site is stored within
  • Number of users
  • Size (MB)
  • Template
  • Number of sub-sites (Webs)
  • Certification date (useful if Site Confirmation and Deletion is turned on)

Prior to running the script please update highlighted with the location to store the output CSV file.

asnp *SharePoint* -ErrorAction SilentlyContinue
#Configure output location for CSV file
$Output = "D:\SiteInventory.csv"
#Create headings in the CSV file
$Headings = "URL","Owner","Content DB","Total Users","Storage Used (MB)",
"Template","Number of Webs","Certification Date"
$Headings -join "," | Out-File -Encoding default -FilePath $Output
#Loop through each Site Collection and output the required properties
Foreach ($S in (Get-SPSite -Limit All))
{
$Info =
$S.URL,
$S.Owner,
$S.ContentDatabase.Name,
$S.RootWeb.SiteUsers.Count,
($S.Usage.Storage /1MB),
($S.RootWeb.WebTemplate + "#" + $S.RootWeb.WebTemplateId),
$S.AllWebs.Count,
$S.CertificationDate
$Info -join "," | Out-File -Encoding default -Append -FilePath $Output
$S.Dispose()
}

Below is an example of the CSV file created.

Brendan Griffin - @brendankarl