To Open the Windows PowerShell Session
:
1. On the Start menu, click All Programs.
2. Click
Microsoft SharePoint 2010
Products.
3. Click SharePoint 2010 Management Shell
Note : You
should have SharePoint_Shell_Access role on the configuration database and you
should be a member of the WSS_ADMIN_WPG local group on the computer where
SharePoint Server 2010 is installed.
Some of the Common Commands and Operations are:
Create Web Application
Variable
$webapp = Get-SPWebApplication
"http://WebapplicationUrl"
Create
SharePoint Site Variable (Instance of SPSite)
$siteurl =
"http://MySharePointSite"
$Oursite=new-object Microsoft.SharePoint.SPSite($siteurl)
Here
we have created a variable Oursite, which contains an instance of type SPSite.
Now you can use it to display all webs in the site
collection.
$Oursite.AllWebs more // List all Webs in the
Site
Create Service Application
Variable
$spapp = Get-SPServiceApplication -Name
"ServiceApplicationDisplayName"
Create a Webapplication:
New
-SPWebApplication -ApplicationPoolName <Name of the application pool> -Name
<Name of the new Web application>
[ -Port <Port on which the Web application
can be accessed>] [-HostHeader <Valid URL assigned to the Web application that
must correlate to the alternate access mapping configuration>]
[-URL <Load-balanced URL for the Web
application>][ -ApplicationPoolAccount <User account that this application pool will run
as>]
Delete WebApplication
Remove-SPWebApplication –identity -URL <http://sitename> -Confirm
Create\Delete a Site Collection:
Create a Site
collection:
Get-SPWebTemplate
$template = Get-SPWebTemplate
"STS#0"
New-SPSite –Url "<URL for the new site collection>"
–OwnerAlias "<domain\user>" –Template $template
Here $template is a
Variable to store the type of template we want to use while creating a site
collection.
Delete a Site Collection:
Remove-SPSite –Identity
<URL> –GradualDelete
Here <URL > is a site Collection Url
.
Back\Restore a content
database
To Backup :
Backup -SPFarm -Directory <Backup folder> -BackupMethod
-Item <Content database name> [-Verbose]
Backup folder - is a
folder to save your backup.
BackupMethod – Can Specify between Full or
Differential.
To Restore:
Restore -SPFarm -Directory <Backup folder> -RestoreMethod
Overwrite -Item <Content database name> [-BackupId] [-Verbose]
If
you don't know the BackupID you can display all the backups using the below
command and get the GUID of the Backup.
Get-SPBackupHistory -Directory
<Backup folder>
You can check all the Backup-Restore Operations
Here
Deploy WebPart Soluiton
Package
Install -SPWebPartPack -LiteralPath "PathToCABorwspFile"
-Name "NameOFWebPart"
PathToCABorwspFile- is the full path to the CAB
file that is being deployed.
NameOFWebPart- is the name of the Web Part
that is being deployed.
Install Activate and
Deactivate Feature using Windows Powershell
Install Feature :
$MyFeatureId = $(Get
-SPFeature -limit all where {$_.displayname -eq
"myfeatureName"}).Id
Install -SPFeature $MyFeatureId
Activate\Enable Feature
:
$singleSiteCollection = Get -SPSite -Identity
http://MySingleSiteCollectionURL
Enable -SPFeature $MyFeatureId -Url
$singleSiteCollection.URL
Deactivate\Disable Feature
:
$singleSiteCollection = Get-SPSite -Identity
http://MySingleSiteCollectionURL
Disable -SPFeature $MyFeatureId -Url
$singleSiteCollection.URL
Command TO
List all the PowerShell Commands
Get-Command –PSSnapin "Get-Command –PSSnapin
"Microsoft.SharePoint.PowerShell"
format-table name > C:\SP2010_PowerShell_Commands.txt