0% found this document useful (0 votes)
45 views

Basic Powershell Commands To Use With Sharepoint 2010

The document provides an overview of useful PowerShell commands for managing SharePoint 2010 environments. Some key commands covered include: 1) Get-SPFarm to retrieve a reference to the SharePoint farm. 2) Get-SPWebApplication and Get-SPSite to retrieve collections of web applications and site collections in the farm. 3) Commands like New-SPWebApplication, New-SPSite, and New-SPContentDatabase for creating new web applications, site collections, and content databases. 4) Get-SPWeb to retrieve collections of websites within a site collection.

Uploaded by

kindhearted
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Basic Powershell Commands To Use With Sharepoint 2010

The document provides an overview of useful PowerShell commands for managing SharePoint 2010 environments. Some key commands covered include: 1) Get-SPFarm to retrieve a reference to the SharePoint farm. 2) Get-SPWebApplication and Get-SPSite to retrieve collections of web applications and site collections in the farm. 3) Commands like New-SPWebApplication, New-SPSite, and New-SPContentDatabase for creating new web applications, site collections, and content databases. 4) Get-SPWeb to retrieve collections of websites within a site collection.

Uploaded by

kindhearted
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

\LB S I 1 L: H1 1 P : , , \\\. KMO.

NAML
L- MAI L : ONLI L L \LB S I 1 LVLRI ZON. NL1
US L AL L COMMANDS A1 O\N RI S K
Basic Powershell commands to use with Sharepoint 2010
Overview.................................................................................................................1
Retrieve a reference to a farm.................................................................................1
Retrieve the collection of web applications in the farm.............................................1
Retrieve the collection of all site collections in the farm...........................................1
Retrieve the collection of web sites..........................................................................2
Create a web application .........................................................................................2
Create a site collection ............................................................................................3
Create a content database ......................................................................................3
Create a new site definition .....................................................................................4
See properties of a site collection: ...........................................................................4
Overview
In Sharepoint 2010 the preferred method to the command line stsadm for processing
commands is the Windows Powershell. The Powershell provides many useful and robust
commands (called cmdlets) that can be accomplished via the command line.
To access a Powershell command line go to the server and select: Start ->.All
Programs -> Microsoft SharePoint 2010 Products-> SharePoint 2010 Management
Shell. Typically I like to right mouse click the Sharepoint 2010 Management Shell and
select run as administrator.
Once loaded the following useful commands can be run:
Retrieve a reference to a farm
Get-SPFarm
Retrieve the collection of web applications in the farm
Get-SPWebApplication
Retrieve the collection of all site collections in the farm
Get-SPSite
Note Get-SPSite is limited to returning 20 site collections if less are desired utilize the
limit switch.
\LB S I 1 L: H1 1 P : , , \\\. KMO. NAML
L- MAI L : ONLI L L \LB S I 1 LVLRI ZON. NL1
US L AL L COMMANDS A1 O\N RI S K
Retrieve the collection of web sites
Get-SPWeb Site http://intranet.mysite.com
This can also be written as:
Get-SPWeb Site http://intranet.mysite.com
Note Get-SPWeb is limited to returning 200 web sites if less are desired utilize the
limit switch, if all sites are to be returned use the all switch.
Create a web application
New-SPWebApplication -Name <Name> -Port <Port> -HostHeader <HostHeader> -URL
<URL> -ApplicationPool <ApplicationPool> -ApplicationPoolAccount
<ApplicationPoolAccount> -DatabaseName <DatabaseName>
<Name> is the name of the new Web application.
<Port> is the port on which the Web application will be created on in IIS.
<HostHeader> is the host header which needs to be in the format server.domain.com.
Note that the Get-Help documentation for the cmdlet states that the format for
<HostHeader> is http://server.domain.com. The documentation is incorrect.
<URL> is the public (load-balanced) URL for the Web application.
<ApplicationPool> is the name of the application pool.
<ApplicationPoolAccount> is the managed account that the application pool will use.
This is required if you are specifying an <ApplicationPool> that does not already exist.
<DatabaseName> is the name of the first content database for the Web application.
Here is a real example:
New-SPWebApplication -Name "KMO Intranet" -Port 80 -HostHeader
"intranet.mysite.com" -URL "http://intranet.mysite.com:80" -ApplicationPool "SharePoint
Web Applications" -ApplicationPoolAccount (Get-SPManagedAccount
"KMO\SP_Service") -DatabaseName "WSS_Content_Intranet"
\LB S I 1 L: H1 1 P : , , \\\. KMO. NAML
L- MAI L : ONLI L L \LB S I 1 LVLRI ZON. NL1
US L AL L COMMANDS A1 O\N RI S K
Create a site collection
New-SPSite -Url "<URL for the new site collection>" ContentDatabase <Content
Database Name> -OwnerAlias "<domain\user>" -Template <Template>
<URL> is the URL of the site collection you want to create.
<Content Database Name> is the name of the content database within which
the site collection should be created. This parameter is optional.
The -OwnerAlias parameters <domain\user> value defines the primary site
collection administrator. The -SecondaryOwnerAlias parameter is used to
define the secondary site collection administrator.
<Template> specifies the site definition for the top-level sitefor example,
BLANKINTERNET#1, the Publishing Site, or STS#0, the Team Site.
Create a content database
New-SPContentDatabase -Name <ContentDbName> -WebApplication
<WebApplicationName>
<ContentDbName> is the name of the content database to create
<WebApplicationName> is the name of the Web application to which the new
database is attached.
Here is a real example:
New-SPContentDatabase -Name WSS_Content_Intranet_Sales -WebApplication
http://intranet.mysite.com
Create a site collection in a specific content database
New-SPSite -Url "http://intranet.mysite.com/sites/Sales" -ContentDatabase
WSS_Content_Intranet_Sales -Name "Sales" -OwnerAlias "KMO\SP_Admin" -Template
"STS#0"
List available site definitions
Get-SPWebTemplate
\LB S I 1 L: H1 1 P : , , \\\. KMO. NAML
L- MAI L : ONLI L L \LB S I 1 LVLRI ZON. NL1
US L AL L COMMANDS A1 O\N RI S K
Create a new site definition
New-SPWeb <Identity> -Name <Name> -Template "STS#0"
Where:
<Identity> is the URL of the new Web site.
<Name> is the name of the Web site.
<Template> specifies the site definition for the Web site, for example,
BLANKINTERNET#1, the Publishing Site, BLOG#0, the Blog Site, or STS#0, the Team
Site.
For example, the following command creates a subweb for blogs beneath the
Sales Web site:
New-SPWeb "http://intranet.mysite.com/sites/Sales/Blogs" -Name "Sales Blogs" -
Template "BLOG#0"
See properties of a site collection:
Get-SPSite "http://intranet.mysite.com/sites/sales" | Get-Member -MemberType
Properties

You might also like