Generate the list of SharePoint application pools matches up GUID and Name.

Get-SPServiceApplicationPool | select Id, Name

Check the size of the site collections in the SharePoint Farm using PowerShell

Get-SPSite -Limit All | select url, @{label=”Size in MB”;Expression={$_.usage.storage}}

Display the above data in more structured format in the descending order of the Site Collection size in MB..

Get-SPSite -Limit ALL | select url, @{label=”Size in MB”;Expression={$_.usage.storage/1MB}} | Sort-Object -Descending -Property “Size in MB” | ConvertTo-Html -title “Site Collections sort by size” | Set-Content data.html

Get the size of each Site Collection in a particular Web Application
use the following command in PowerShell :

Get-SPWebApplication http://webapplicationurl | Get-SPSite -Limit all | select url, @{label=”Size in MB”;Expression={$_.usage.storage/1MB}} | Sort-Object -Descending -Property “Size in MB” | Format-Table –AutoSize


Download deployed SharePoint 2010 solutions using PowerShell

$dirName = “c:\Solutions”
foreach ($solution in Get-SPSolution)
$id = $Solution.SolutionID
$title = $Solution.Name
$filename = $Solution.SolutionFile.Name

Use the following script to download a particular solution deployed to the farm:

$farm = Get-SpFarm$SolutionFile = $farm.Solutions.Item(“SolutionName.wsp”).SolutionFile



CPU usage, Drive utilization, Memory utilization for the servers – using powershell

############################################################################ This scripts check the server Avrg CPU and Memory utlization along with C drive
## disk utilization and sends an email to the receipents included in the script
$ServerListFile = “E:\ram\ServerList.txt”
$ServerList = Get-Content $ServerListFile -ErrorAction SilentlyContinue
$Result = @()
ForEach($computername in $ServerList)
$AVGProc = Get-WmiObject -computername $computername win32_processor |
Measure-Object -property LoadPercentage -Average | Select Average
$OS = gwmi -Class win32_operatingsystem -computername $computername |
Select-Object @{Name = “MemoryUsage”; Expression = {“{0:N2}” -f ((($_.TotalVisibleMemorySize – $_.FreePhysicalMemory)*100)/ $_.TotalVisibleMemorySize) }}
$vol = Get-WmiObject -Class win32_Volume -ComputerName $computername -Filter “DriveLetter = ‘C:'” |
Select-object @{Name = “C PercentFree”; Expression = {“{0:N2}” -f  (($_.FreeSpace / $_.Capacity)*100) } }
$result += [PSCustomObject] @{
        ServerName = “$computername”
        CPULoad = “$($AVGProc.Average)%”
        MemLoad = “$($OS.MemoryUsage)%”
        CDrive = “$($vol.’C PercentFree’)%”
    $Outputreport = “<HTML><TITLE> Server Health Report </TITLE>
                     <BODY background-color:peachpuff>
                     <font color =””#99000″” face=””Microsoft Tai le””>
                     <H2> Server Health Report </H2></font>
                     <Table border=1 cellpadding=0 cellspacing=0>
                     <TR bgcolor=gray align=center>
                       <TD><B>Server Name</B></TD>
                       <TD><B>Avrg.CPU Utilization</B></TD>
                       <TD><B>Memory Utilization</B></TD>
                       <TD><B>C Drive Utilizatoin</B></TD></TR>”
    Foreach($Entry in $Result)
          if((($Entry.CpuLoad) -or ($Entry.memload)) -ge “80”)
            $Outputreport += “<TR bgcolor=red>”
            $Outputreport += “<TR>”
          $Outputreport += “<TD>$($Entry.Servername)</TD><TD align=center>$($Entry.CPULoad)</TD><TD align=center>$($Entry.MemLoad)</TD><TD align=center>$($Entry.Cdrive)</TD></TR>”
     $Outputreport += “</Table></BODY></HTML>”
$Outputreport | out-file E:\Ram\Test.htm

Below is the powershell script to get the custom site template ID

$url = “http://test/”

$site= new-Object Microsoft.SharePoint.SPSite($url )
$loc= [System.Int32]::Parse(1033)
$templates= $site.GetWebTemplates($loc)
foreach ($child in $templates){ write-host $child.Name “ ” $child.Title}



Administering SharePoint 2013 Using PowerShell: Prerequisites

You need farm administrator access to a SharePoint 2013 farm to complete the exercises in this article.

  • Open a remote desktop session to one of your SharePoint servers in your farm.
  • Open PowerShell or the SharePoint Management Shell.
  • If you use PowerShell ISE or if you do not have the SharePoint commands available in the shell you’re using, load the SharePoint commands with this PowerShell command: Add-PSSnapin Microsoft.SharePoint.PowerShell

Find the SharePoint 2013 Content Databases with PowerShell

When working with your content databases, you’ll use the Get-SPContentDatabase cmdlet to find and list them. This command will be the foundation of working with your content databases, so let’s get familiar with it.

List all content databases in SharePoint 2013 with PowerShell

Use the Get-SPContentDatabase with no parameters to get the list of all content databases in your SharePoint 2013 farm.


List all content databases in a specific web application

Use the –WebApplicationto specify all of the content databases used by a specific web app.

Get-SPContentDatabase –WebApplication “http://mysharepointapp.local”

Show a single content database using PowerShell

Use the –Identityparameter of Get-SPContentDatabase to return a single content database. The Identity can be either the friendly name of the content database or the actual ID of the database, which is a long GUID that you’ll only get at by scripting or copy/pasting it.

Get-SPContentDatabase –Identity “WSS_Content”
Get-SPContentDatabase –Identity “GUID-OF-DATABASE-123456-1234”

You can also omit the -Identity parameter. If you add in a name or a GUID, Get-SPContentDatabase knows what you’re asking for and returns the content database.

Administering SharePoint 2013 with PowerShell: Identity cmdlet

Find which Site Collections are using a content database

Isolate the content database by using the Identity parameter of Get-SPContentDatabase, then send the SPContentDatabase object through the pipeline to a Get-SPSitecmdlet.

Get-SPContentDatabase “WSS_Content” | Get-SPSite

Find what content database a SharePoint 2013 site collection is using

Remember that in SharePoint 2013 a site collection can only store its content in a single content database. To find out which content database a particular site collection is using, use the -Site parameter on the Get-SPContentDatabase cmdlet.

Get-SPContentDatabase –Site “http://your.sharepoint.local/sitecollection”


Create a new content database for a web application

Creating a content database can be done with only two parameters, -Name and -WebApplication.

New-SPContentDatabase –Name “HRContentDB” –WebApplication “http://StaffPortal”

If you have multiple departments with their own site collections, and you want to keep of their content in a separate database, you can easily create all of their content databases at once.

“HR”,”Legal”,”Sales”,”Marketing”,”Accounting” | Foreach-Object {
New-SPContentDatabase “$($_)_ContentDB” “http://StaffPortal”

While you cannot pipe items directly into the New-SPContentDatabase, it expects that the first thing you input is the name off the content database, and the second thing you enter is the web application. If you enter those two parameter values in that order, you don’t have to specify the parameter names.

New-SPContentDatabase “HRContentDB” “http://StaffPortal

It works just the same as specifying “-Name” and “-WebApplication.”

Administering SharePoint 2013 with PowerShell: BatchCreation

Note: The “$($_)_” is used to put the “HR,””Legal,” etc. in line with the rest of the database name. Specifying just “$__Content” would leave the string messed up since it can’t properly resolve the variable name. Use a $($_) to resolve variable that is inside the parenthesis as a variable. Once it’s resolved, it places it in the string. Try it for yourself by entering “HR”,”Legal” | % {“$($_)_Content”} into PowerShell.

Administering Content Databases with PowerShell

You can make several changes to content databases with the Set-SPContentDatabase. Just like when you piped the results of Get-SPContentDatabase into Get-SPSite to find sites that are attached to it, you can pipe the results of Get-SPContentDatabase into Set-SPContentDatabase to perform administration on those databases.

The Set-SPContentDatabase will find content databases by name or GUID without needing the Get-SPContentDatabase to process first. But if you want to work with the content database of a particular site then you’ll need to use the “-Site”parameter from Get-SPContentDatabase, because that parameter doesn’t work in Set-SPContentDatabase.

Examples of what will work:

Set-SPContentDatabase “HR_ContentDB”

Get-SPContentDatabase “http://hr.sharepoint.local” | Set-SPContentDatabase

Move a site collection to a different content database

This property is owned by the site, not the content database, so perform this operation using the SPSite cmdlets.

Get-SPSite “http://legal.sharepoint.local” | Move-SPSite –DestinationDatabase “Legal_ContentDB”

Set the maximum number of sites a content database can have

Use the –MaxSiteCount parameter to specify a positive integer.

Set-SPContentDatabase “HR_ContentDB” –MaxSites 1

You can also specify a warning number to get an alert when the maximum number of sites is approaching.

Set-SPContentDatabase “HR_ContentDB” –MaxSites 10 –WarningSiteCount 7

Moving a Content Database to a Different Web Application

Moving a content database to a different web application is a two-step process. First, you have to dismount the database from its current web application. Second, you can attach it to a different web application.

Get-SPContentDatabase “Marketing_ContentDB” | Dismount-SPContentDatabase –Confirm:$False
Mount-SPContentDatabase –Name “Marketing_ContentDB” –WebApplication “http://marketing.sharepoint.local” –Confirm:$false

Removing Content Databases in SharePoint 2013 with PowerShell

Use the Remove-SPContentDatabase cmdlet to delete them completely from the SQL server, or use Dismount-SPContentDatabase to remove an unwanted content databases from your farm but still leave it on the SQL Server without deleting it.

Remove a content database from the farm but not delete it on the SQL server

The Dismount-SPContentDatabase cmdlet doesn’t delete the content database. This makes it easy to migrate the database to a different web application or SharePoint farm. Note that this is the same command we used as the first step in moving the content database to a different web application.

Dismount-SPContentDatabase –Identity “HR_ContentDB”

Remove and delete a content database from the farm

The Remove-SPContentDatabase removes the content database and deletes it completely.

Remove-SPContentDatabase –Identity “HR_ContentDB”

Original Post :https://www.petri.com/administer-sharepoint-2013-powershell-manage-content-databases 



Backup and Restore Site Collections in SharePoint 2010/2013

Powershell commands are very straightforward:

Get-SPSite -ContentDatabase SourceContentDbName | Move-SPSite -DestinationDatabase DestinationContentDbName

Add-SPSolution “d:\path\customsolution.wsp”
Install-SPSolution -Identity “customsolution.wsp” -WebApplication http://webappurl/ -GACDeployment

Test-SPContentDatabase –Name contentdb –WebApplication http://webappurl/

Mount-SPContentDatabase –Name contentdb –WebApplication http://webappurl/


Backup-SPSite -Identity http://web/path/site -Path D:\path\site.bak –Verbose
Restore-SPSite -Identity http://web/path/site -Path D:\path\site.bak -Force –Verbose
Restore-SPSite -Identity http://web/path/site -DatabaseServer DBSERVER -DatabaseName SP_Content_Database -Path D:\Path\site.bak -Force -Verbose


In this script, we set maximum number of sites to 3 for the content database that contains site collection “http://web/path/site”:

Get-SPContentDatabase -Site http://web/path/site | Set-SPContentDatabase -MaxSiteCount 3 -WarningSiteCount 0

Known Issues – Backup and Restore Process Sensitivity to Environment Version

When you are backing and restoring site collections between different server environments one of the key things that you need to pay particular attention to is SharePoint patch level. The environments you are backing and restoring to must be at the same level.

Here is an example of error when you try to restore a site collection backed up in SharePoint at newer patch level.
After running the following restore command in Powershell, we see a very convoluted error message that has nothing to do with the actual error:


Restore-SPSite -Identity http://web/path/site -DatabaseServer DBSERVER -DatabaseName SP_Content_Database -Path D:\Path\site.bak -Force -Verbose

Exception: DirectoryNotFoundException – in reality has nothing to do with the actual error, which we can see in ULS log tells us that there is a version mismatch, and that is why our restore is failing.

Blog: Backup and Restore Site Collection in SP2013