Applies to: SharePoint Server 2010, SharePoint Foundation 2010

Topic Last Modified: 2010-07-21

Returns all site collections that match the given criteria.

Get-SPSite [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-Filter <ScriptBlock>] [-Limit <String>] [-WebApplication <SPWebApplicationPipeBind>] [-WhatIf [<SwitchParameter>]]
Get-SPSite [-Identity] <SPSitePipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-Filter <ScriptBlock>] [-Limit <String>] [-Regex <SwitchParameter>] [-WhatIf [<SwitchParameter>]]
Get-SPSite -ContentDatabase <SPContentDatabasePipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-Filter <ScriptBlock>] [-Limit <String>] [-WhatIf [<SwitchParameter>]]
Get-SPSite -SiteSubscription <SPSiteSubscriptionPipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-Filter <ScriptBlock>] [-Limit <String>] [-WhatIf [<SwitchParameter>]]

This cmdlet contains more than one parameter set. You may only use parameters from one parameter set, and you may not combine parameters from different parameter sets. For more information about how to use parameter sets, see Cmdlet Parameter Sets.

The Get-SPSite cmdlet returns either a single site that matches the Identity parameter, or all the sites that match the Filter parameter for the specified scope. The scopes are the WebApplication, ContentDatabase , and SiteSubscription parameters. If none of these scopes is provided, the scope is the farm. If the scope is specified with no Filter parameter, all sites in that scope are returned.

The Identity parameter supports providing a partial URL that ends in a wildcard character (*). All site collections that match this partial URL for the specified scope are returned. Additionally, if the Regex parameter is provided, the Identity parameter is treated as a regular expression and any site collection with a URL provided in the given scope that matches the expression is returned.

The Filter parameter is a server-side filter for certain site collection properties that are stored in the content database; without the Filter parameter, filtering on these properties is a slow process. These site collection properties are Owner, SecondaryOwner, and LockState. The Filter parameter is a script block that uses the same syntax as a Where-Object statement, but is run server-side for faster results.

Valid values for LockState are, Unlock, NoAdditions, ReadOnly, NoAccess.

It is important to note that every site collection returned by the Get-SPSite cmdlet is automatically disposed of at the end of the pipeline. To store the results of Get-SPSite in a local variable, the Start-SPAssignment and Stop-SPAssignment cmdlets must be used to avoid memory leaks.


Parameter Required Type Description




Specifies the URL or GUID of the site collection to get.

The type must be a valid URL, in the form http://server_name or http://server_name/sites/sitename, or a valid GUID (for example, 12345678-90ab-cdef-1234-567890bcdefgh).




Specifies the GUID of the content database from which to list site collections.

The type must be a valid database name, in the form SPContentDB01, or a valid GUID (for example, 12345678-90ab-cdef-1234-567890bcdefgh).




Specifies the site subscription from which to get site collections.

The type must be a valid URL, in the form http://server_name or a valid GUID (for example, 12345678-90ab-cdef-1234-567890bcdefgh).




Manages objects for the purpose of proper disposal. Use of objects, such as SPWeb or SPSite, can use large amounts of memory and use of these objects in Windows PowerShell scripts requires proper memory management. Using the SPAssignment object, you can assign objects to a variable and dispose of the objects after they are needed to free up memory. When SPWeb, SPSite, or SPSiteAdministration objects are used, the objects are automatically disposed of if an assignment collection or the Global parameter is not used.

When the Global parameter is used, all objects are contained in the global store. If objects are not immediately used, or disposed of by using the Stop-SPAssignment command, an out-of-memory scenario can occur.




Prompts you for confirmation before executing the command. For more information, type the following command: get-help about_commonparameters




Specifies the script block of the server-side filter to apply.

The type must be a valid filter name and value in the form {$_PropertyName <operator> "filterValue"}.

Valid operators are: EQ, NE, LIKE, NOTLIKE.




Limits the maximum number of site collections to return. The default value is 200.

The type must be a valid non-negative number. Specify ALL to return all site collections for the given scope.




When used, the URL provided for the Identity parameter to be treated as a regular expression.




Specifies the URL, GUID, or name of the Web application from which to list sites.

The type must be a valid URL, in the form http://server_name, a valid GUID (for example, 12345678-90ab-cdef-1234-567890bcdefgh); or the Web application name (for example, WebApplication1212).




Displays a message that describes the effect of the command instead of executing the command. For more information, type the following command: get-help about_commonparameters

------------------EXAMPLE 1---------------------

Get-SPSite 'http://sitename' | Get-SPWeb -Limit All | Select Title

This example gets the collection of subweb titles in site collection at http://sitename.

------------------EXAMPLE 2---------------------

Get-SPSite -ContentDatabase "b399a366-d899-4cff-8a9b-8c0594ee755f" | Format-Table -Property Url, Owner, SecondaryOwner

This example gets a subset of data from all of the sites in the content database b399a366-d899-4cff-8a9b-8c0594ee755f.

------------------EXAMPLE 3---------------------

Start-SPAssignment -Global
$s = Get-SPSite -Identity http://MyApp/Sites/Site1
Stop-SPAssignment -Global

This example gets the sites specified by the Identity parameter and inserts the results in the variable s

The previous example uses the Global method of assignment collection. The Global method is easier to use but the contents of this object grows quickly. Be careful not to run a Get-SPSite command that returns many results while global assignment is enabled.

------------------EXAMPLE 4---------------------

$GC = Start-SPAssignment
$Sites = $GC | Get-SPSite -Filter {$_.Owner -eq "DOMAIN\JDoe"} -Limit 50
Stop-SPAssignment $GC

This example gets the first 50 sites owned by user DOMAIN\JDoe by using a server-side query, and assigns them to a local variable.

This example uses advanced assignment collection methods.

------------------EXAMPLE 5---------------------

Get-SPWebApplication http://sitename | Get-SPSite -Limit All |ForEach-Object {$sum=0}{ $sum+=$_.Usage.Storage }{$sum}

This example shows a command that returns the sum of the disk space usage for all sites in a given Web application.

------------------EXAMPLE 6---------------------

Get-SPSite -Identity "http://localserver/(my|personal)/sites" -Regex

This example returns all sites that match the given regular expression.

The Quotes on the Identity parameter are required when the Regex parameter is used.

------------------EXAMPLE 7---------------------

Get-SPSite http://sitename/sites/teams/* -Limit 100

This example gets up to 100 of the sites under the URL http://sitename/sites/teams.

------------------EXAMPLE 8---------------------

Get-SPSite | select url, @{Expression={$_.Usage.Storage}}

This example gets the amount of storage used by a site collection, by using the storage field of the .UsageInfo property.