Like This ...

SharePoint 2010 PowerShell Commands

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 [ -Port ] [-HostHeader ] [-URL ][ -ApplicationPoolAccount ]

Delete WebApplication
Remove-SPWebApplication –identity -URL -Confirm

Create\Delete a Site Collection:
Create a Site collection:
Get-SPWebTemplate
$template = Get-SPWebTemplate "STS#0"
New-SPSite –Url "" –OwnerAlias "" –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 –GradualDelete
Here is a site Collection Url .


Back\Restore a content database
To Backup :
Backup -SPFarm -Directory -BackupMethod -Item [-Verbose]
Backup folder - is a folder to save your backup.
BackupMethod – Can Specify between Full or Differential.

To Restore:
Restore -SPFarm -Directory -RestoreMethod Overwrite -Item [-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
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
blog comments powered by Disqus