Edit

Share via


Get-SPWeb

Returns all subsites that match the given criteria.

Syntax

Default (Default)

Get-SPWeb
    [[-Identity] <SPWebPipeBind>]
    [-AssignmentCollection <SPAssignmentCollection>]
    [-Confirm]
    [-Filter <ScriptBlock>]
    [-Limit <String>]
    [-Regex]
    [-Site <SPSitePipeBind>]
    [-WhatIf]
    [<CommonParameters>]

Description

The Get-SPWeb cmdlet returns all subsites that match the scope given by the Identity parameter. All subsites that meet the criteria are returned.

The Identity can be either the full URL or a relative path. If you specify a relative path, you must also specify the Site parameter to identify the site collection from which to return the subsite.

The Identity parameter also supports providing a partial URL that ends in a wildcard character (*). All subsites 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 subweb with a URL provided in the given scope that matches the expression is returned.

The Filter parameter is a server-side filter for certain subsite properties that are stored in the content database; without the Filter parameter, filtering on these properties is a slow process. These subsite properties are Template and Title. 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.

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

For permissions and the most current information about Windows PowerShell for SharePoint Products, see the online documentation at SharePoint Server Cmdlets.

Examples

EXAMPLE 1

Get-SPWeb -site https://sitename/sites/site1

This example returns all the subwebs in a given site collection.

EXAMPLE 2

Get-SPWeb -Site https://sitename/sites/site1  -filter {$_.Template -eq "STS#0"}

This example displays all subsites that use the "STS#0" template.

EXAMPLE 3

Start-SPAssignment -Global

C:\PS>$w = Get-SPWeb https://sitename

C:\PS>$w.set_SiteLogoUrl("https://PathToImage/test.jpg")

C:\PS>$w.Update()

Stop-SPAssignment -Global

This example demonstrates how to save a subsite as a variable and to call object model methods on the SPAssignment object.

Parameters

-AssignmentCollection

Applicable: SharePoint Server 2010, SharePoint Server 2013, SharePoint Server 2016, SharePoint Server 2019

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.

Parameter properties

Type:SPAssignmentCollection
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False

-Confirm

Applicable: SharePoint Server 2010, SharePoint Server 2013, SharePoint Server 2016, SharePoint Server 2019

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

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False
Aliases:cf

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Filter

Applicable: SharePoint Server 2010, SharePoint Server 2013, SharePoint Server 2016, SharePoint Server 2019

Specifies the server-side filter to use for the specified scope.

The type must be a valid filter in the form {filterName <operator> "filterValue"}.

Parameter properties

Type:ScriptBlock
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Identity

Applicable: SharePoint Server 2010, SharePoint Server 2013, SharePoint Server 2016, SharePoint Server 2019

Specifies the name or full or partial URL of the subsite. If you use a relative path, you must specify the Site parameter.

A valid URL in the form https://server_name or a relative path in the form of /SubSites/MySubSite.

Parameter properties

Type:SPWebPipeBind
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:1
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Limit

Applicable: SharePoint Server 2010, SharePoint Server 2013, SharePoint Server 2016, SharePoint Server 2019

Limits the maximum number of subsites to return. The default value is 200. To return all sites, enter ALL

The type must be a valid number greater than 0 or ALL.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Regex

Applicable: SharePoint Server 2010, SharePoint Server 2013, SharePoint Server 2016, SharePoint Server 2019

Specifies the URL that is provided by the Identity parameter is treated as a regular expression.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Site

Applicable: SharePoint Server 2010, SharePoint Server 2013, SharePoint Server 2016, SharePoint Server 2019

Specifies the URL or GUID of the site collection from which to list subsites.

The type must be a valid URL, in the form of https://server_name; a GUID, in the form 1234-5678-9807, or an SPSite object.

Parameter properties

Type:SPSitePipeBind
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False

-WhatIf

Applicable: SharePoint Server 2010, SharePoint Server 2013, SharePoint Server 2016, SharePoint Server 2019

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

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False
Aliases:wi

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.