Sunday, October 27, 2013

SharePoint PowerShell Script Feature Activate and Deactivate


1) Run script in windows power shell first run line

Add-PSSnapin ‘Microsoft.SharePoint.PowerShell’



2) Deploy webpart  using power shell
 Add-SPSolution “D:\Deploy\MySharePointSolution.wsp“

Install-SPSolution –Identity MySharePointSolution.wsp –WebApplication http://myspwebapp –GACDeployment

If you would like to add the solution as sandboxed, you would use the Install-SPUserSolution command instead. To upgrade a solution, we specify which solution is to be updated and with which new solution file:

Update-SPSolution –Identity MySharePointSolution.wsp –LiteralPath “D:\Deploy\MySharePointSolution.wsp” –GacDeployment

To retract and remove a solution, we use the following commands:

Uninstall-SPSolution –Identity MySharePointSolution.wsp –WebApplication http://myspwebapp
Remove-SPSolution–Identity MySharePointSolution.wsp

Enable-SPFeature –Identity MyFeatureNameOrGuid –url http://myspwebapp
Disable-SPFeature –Identity MyFeatureNameOrGuid –url http://myspwebapp



Listing features on Farm, Site Collection and Site

The main cmdlet used within powershell to list features is the Get-SPFeature cmdlets. To show all the features on the farm listed by display name and sorted use this:


Get-SPFeature | Sort -Property DisplayName

To show all the features on the Farm grouped by scope in a table use:


Get-SPFeature | Sort -Property DisplayName, Scope | FT -GroupBy Scope DisplayName

To see all features for a Web Application:


Get-SPFeature -WebApplication http://webapplication

To see all features for a Site Collection:


Get-SPFeature -Site http://sitecollection

To see all features for a Site:


Get-SPFeature -Web http://siteurl

Remember for some more information relating to the features you can use:


Get-SPFeature -Web http://siteurl | Format-List

To see all the members that a feature definition has use:


Get-SPFeature -Web http://siteurl | Get-Member



Enabling and Disabling Features

To disable and enable features is all pretty easy once again using the Disable-SPFeature and Enable-SPFeature cmdlets but there is a trick. You need the name of the feature folder that contains the actual feature not what is displayed in the UI so be careful:


Enable-SPFeature -Identity "Hold" -URL http://url




You can apply this to any Site and Site Collection scoped features.
Obviously to disable a feature just use the same syntax but with the Disable-Feature cmdlet


Disable-SPFeature -Identity "Hold" -URL http://url

Remember though that the -Identity is the DisplayName property of the feature, not the text displayed on the UI which is actually retrieved from a resources file.
For example the Document Sets feature looks like below in the SharePoint interface:


But to actually enable it you have to use the following cmdlet:


Enable-SPFeature -Identity DocumentSet -URL http://url

Installing and Uninstalling Features

Once again this is pretty straight forward and is really made up of only two cmdlets: Install-SPFeature and Uninstall-SPFeature

To install a feature you need to specify the name of the folder that your feature contains:




Install-SPFeature "FeatureFolderName"

To uninstall simply use the same Uninstall-Feature command with the same parameters:


Uninstall-SPFeature -Identity "MyCustomFeature"

0 comments:

Post a Comment