SharePoint Powershell for Solution Deployment (WSP)
[ 2 ] August 8, 2010 | Michal Pisarek
So we have covered a couple of areas with PowerShell but on of the most used, especially for those of use that like to play around with SharePoint, is the addition of solutions and features to our farms.
Now that we have PowerShell available in SharePoint 2010 you should really be using this to add your solutions, even though you can still do this with stsadm (but come on who wants to)
MOSS Solution Commands
In the 2007 days there were essentially 5 different commands used for dealing with solutions:
We added solutions using the addsolution command to the Farm:
1
stsadm –o addsolution –filename "C:\Deployment\MySharePointSolutionPackage.wsp"
To deploy the solution we used the deploysolution command:
1
stsadm –o deploysolution –name MySharePointSolutionPackage.wsp –url http://webapplication –allowgacdeployment –immediate
To upgrade a solution we used the upgradesolution command:
1
stsadm –o upgradesolution –name MySharePointSolutionPackage.wsp –filename "C:\Deployment\MySharePointSolutionPackage.wsp" –immediate
To retract and remove a solution we used the retractsolution and removesolution commands respectively:
1
stsadm –o retractsolution –name MySharePointSolutionPackage.wsp –url http://webapplication –immediate
2
stsadm –o deletesolution –name MySharePointSolutionPackage.wsp
Powershell Solution Cmdlets
Adding
To add a solution to the Farm solution store use the Add-SPSolution cmdlet:
1
Add-SPSolution –LiteralPath "C:\Deployment\MySharePointSolutionPackage.wsp"
To add a Sandboxed solution use the Add-SPUserSolution cmdlet:
1
Add-SPUserSolution –LiteralPath "C:\Deployment\MySharePointSolutionPackage.wsp" –Site http://webapplication/sitecollection
Installing
To install ( commonly known as deploy) a Farm Solution we use the Install-SPSolution cmdlet:
1
Install-SPSolution –Identity MySharePointSolutionPackage.wsp –WebApplication http://webapplication –GACDeployment
To install ( commonly known as deploy) a Sandboxed Solution we use the Install-SPUserSolution cmdlet:
1
Install-SPUserSolution –Identity MySharePointSolutionPackage.wsp –Site http://webapplication/sitecollection
Updating
To update (know as upgrade in stsadm) a Farm solution use the Update-SPSolution cmdlet:
1
Update-SPSolution –Identity MySharePointSolution.wsp –LiteralPath “C:\Deployment\MySharePointSolutionPackage.wsp” –GacDeployment
To update (know as upgrade in stsadm) a Sandbox solution use the Update-SPUserSolution cmdlet:
1
Update-SPUserSolution –Identity MySharePointSolution.wsp –Site http://webapplication/site –ToSolution MySharePointSolutionPackage.wsp
Removing
To uninstall and remove FARM level solutions use the Uninstall-SPSolution and Remove-SPSolution cmdlets:
1
Uninstall-SPSolution –Identity MySharePointSolution.wsp –WebApplication http://webapplication
2
Remove-SPSolution –Identity MySharePointSolution.wsp
To uninstall and remove Sandbox solutions use the Uninstall-SPSolution and Remove-SPSolution cmdlets:
1
Uninstall-SPUserSolution –Identity MySharePointSolution.wsp –Site http://webapplication/sitecollection
2
Remove-SPUserSolution –Identity MySharePointSolution.wsp –Site http://webapplication/sitecollection
To get a list of all of the powershell cmdlets that deal with solutions use:
1
Get-Command –noun *SPSolution*
To run all of the Administrative jobs that are queued:
1
Start-SPAdminJob
So that’s it, next time let’s looks at some basic feature powershell cmdlets as well
Search This Blog
Wednesday, December 21, 2011
Working with Solutions
Working with Solutions
In the ‘old’ days (let us not forget that the stsadm is still there and we have a lot of SharePoint 2007 installations across the globe), the following stsadm command could be used to add a SharePoint solution to SharePoint:
stsadm –o addsolution –filename “D:\Deploy\MySharePointSolution.wsp“
We used the following command to deploy the solution once installed to a specific web application:
stsadm –o deploysolution –name MySharePointSolution.wsp –url http://myspwebappp –allowgacdeployment –immediate
If we would upgrade an existing solution, we would use the following:
stsadm –o upgradesolution –name MySharePointSolution.wsp –filename “D:\Deploy\MySharePointSolution.wsp” -immediate
And finally, we used the following commands to retract and delete a specific solution from the web application:
stsadm –o retractsolution –name MySharePointSolution.wsp –url http://myspwebapp –immediate
stsadm –o deletesolution –name MySharePointSolution.wsp
Now, let us see how we could do above operations with PowerShell. For this, we use the following PowerShell commands:
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
Working with features
Similarly, commands exist for working with features. The stsadm equivalents:
stsadm –o activatefeature –name MyFeatureName –url http://myspwebapp
stsadm –o deactivatefeature –name MyFeatureName –url http://myspwebapp
Needless to say, there are easy equivalents in PowerShell:
Enable-SPFeature –Identity MyFeatureNameOrGuid –url http://myspwebapp
Disable-SPFeature –Identity MyFeatureNameOrGuid –url http://myspwebapp
As you can see, PowerShell will completely replace stsadm as the administrative command line tool for SharePoint. Better to start using it as the next version of SharePoint will not have a stsadm command line tool I suspect. To conclude, let us take a look at a script that enables a certain feature across all site collections and sites in a farm. As an example, I have taken the SharePoint Server Enterprise Site Features feature with ID 0806d127-06e6-447a-980e-2e90b03101b8.
Add-PSSnapin Microsoft.SharePoint.PowerShell
$WebApplications = Get-SPWebApplication
foreach ($webapp in $WebApplications) {
$Id = $webapp.Id
Write-Host “Processing web application $Id …”
$sites = $webapp.Sites
foreach ($site in $sites) {
Write-Host Processing site $site.Id
$webs = $site.AllWebs
foreach ($web in $webs) {
Write-Host Processing web $web.Title
if ($web.Features["0806d127-06e6-447a-980e-2e90b03101b8"] -eq $null) {
Enable-SPFeature -Identity 0806d127-06e6-447a-980e-2e90b03101b8 -url $web.Url -Confirm:$false
} else {
Disable-SPFeature -Identity 0806d127-06e6-447a-980e-2e90b03101b8 -url $web.Url -Confirm:$false
}
}
}
}
Please note though that above script will work for small site collections. But for larger object hierarchies, you will need to include proper memory management (SPAssignment) to ensure proper release of memory.
===================================================
Note:
The STSADM command line application worked well with previous versions of SharePoint. But the world is progressing and PowerShell will be the new administrative tool for SharePoint. In previous articles, I already showed some amazing powerful scripts that otherwise would require more lines of code. PowerShell offers some great advantages in large farms, as they can be run remotely on target machines, can be signed and therefore be controlled. Building up a repository of scripts or cmdlets to execute common tasks would be worthwhile in the long run.
First off an important thing to note here that this will only work with SharePoint 2010. There are no PowerShell snapins available for 2007, although you could create your own off course. And when run from a SharePoint 2010 Management Shell, the snapins are loaded automatically. But what if you just use the ‘normal’ console? Well, then you would have to register the snapin yourself. Fortunately, MS has already created the PowerShell script that is needed, located at:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Config\PowerShell\Registration\SharePoint.ps1.
You could include this script in your scripts to be run first, or just include the command that registers the snapin:
Add-PSSnapin Microsoft.SharePoint.PowerShell
This article covers one of the most basic tasks one would do when administrating SharePoint: Deploy SharePoint solutions (WSP) and enable/disable features.
http://myspexp.com/category/sharepoint-or-custom-development/
http://myspexp.com/category/sharepoint-or-custom-development/
Deploying a WSP solution to SharePoint 2010
Set up your path in your environmental table…
SET PATH=%PATH%;C:\Program Files\Common Files\Microsoft Shared\web server extensions\14\BIN
Locate Your DEBUG or RELEASE folder
CD\DEPLOY
Add your solution
stsadm -o addsolution -filename YESPrep_Redirection.wsp
Deploy your solution
stsadm -o deploysolution -name YESPrep_Redirection.wsp -url http://nav-test.yesprep.local -allowgacdeployment -immediate
pause
——————
To Remove it before deploying another solution follow the steps below:
Set up your path in your environmental table…
SET PATH=%PATH%;C:\Program Files\Common Files\Microsoft Shared\web server extensions\14\BIN
Locate Your DEBUG or RELEASE folder
CD\DEPLOY
Remove your solution
stsadm -o retractsolution -name YESPrep_Redirection.wsp -URL http://cssp02-staging -immediate
Remove your solution
stsadm -o deletesolution -name YESPrep_Redirection.wsp
Lastly make sure that you add the web part into the gallery (upload the *.webpart file)
Using PowerShell to deploy SharePoint Solutions (WSP)
Using PowerShell to deploy SharePoint Solutions (WSP)
Posted by Patrick Boom on May 31, 2010
The STSADM command line application worked well with previous versions of SharePoint. But the world is progressing and PowerShell will be the new administrative tool for SharePoint. In previous articles, I already showed some amazing powerful scripts that otherwise would require more lines of code. PowerShell offers some great advantages in large farms, as they can be run remotely on target machines, can be signed and therefore be controlled. Building up a repository of scripts or cmdlets to execute common tasks would be worthwhile in the long run.
First off an important thing to note here that this will only work with SharePoint 2010. There are no PowerShell snapins available for 2007, although you could create your own off course. And when run from a SharePoint 2010 Management Shell, the snapins are loaded automatically. But what if you just use the ‘normal’ console? Well, then you would have to register the snapin yourself. Fortunately, MS has already created the PowerShell script that is needed, located at:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Config\PowerShell\Registration\SharePoint.ps1.
You could include this script in your scripts to be run first, or just include the command that registers the snapin:
Add-PSSnapin Microsoft.SharePoint.PowerShell
This article covers one of the most basic tasks one would do when administrating SharePoint: Deploy SharePoint solutions (WSP) and enable/disable features.
Working with Solutions
In the ‘old’ days (let us not forget that the stsadm is still there and we have a lot of SharePoint 2007 installations across the globe), the following stsadm command could be used to add a SharePoint solution to SharePoint:
stsadm –o addsolution –filename “D:\Deploy\MySharePointSolution.wsp“
We used the following command to deploy the solution once installed to a specific web application:
stsadm –o deploysolution –name MySharePointSolution.wsp –url http://myspwebappp –allowgacdeployment –immediate
If we would upgrade an existing solution, we would use the following:
stsadm –o upgradesolution –name MySharePointSolution.wsp –filename “D:\Deploy\MySharePointSolution.wsp” -immediate
And finally, we used the following commands to retract and delete a specific solution from the web application:
stsadm –o retractsolution –name MySharePointSolution.wsp –url http://myspwebapp –immediate
stsadm –o deletesolution –name MySharePointSolution.wsp
Now, let us see how we could do above operations with PowerShell. For this, we use the following PowerShell commands:
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
Working with features
Similarly, commands exist for working with features. The stsadm equivalents:
stsadm –o activatefeature –name MyFeatureName –url http://myspwebapp
stsadm –o deactivatefeature –name MyFeatureName –url http://myspwebapp
Needless to say, there are easy equivalents in PowerShell:
Enable-SPFeature –Identity MyFeatureNameOrGuid –url http://myspwebapp
Disable-SPFeature –Identity MyFeatureNameOrGuid –url http://myspwebapp
As you can see, PowerShell will completely replace stsadm as the administrative command line tool for SharePoint. Better to start using it as the next version of SharePoint will not have a stsadm command line tool I suspect. To conclude, let us take a look at a script that enables a certain feature across all site collections and sites in a farm. As an example, I have taken the SharePoint Server Enterprise Site Features feature with ID 0806d127-06e6-447a-980e-2e90b03101b8.
Add-PSSnapin Microsoft.SharePoint.PowerShell
$WebApplications = Get-SPWebApplication
foreach ($webapp in $WebApplications) {
$Id = $webapp.Id
Write-Host “Processing web application $Id …”
$sites = $webapp.Sites
foreach ($site in $sites) {
Write-Host Processing site $site.Id
$webs = $site.AllWebs
foreach ($web in $webs) {
Write-Host Processing web $web.Title
if ($web.Features["0806d127-06e6-447a-980e-2e90b03101b8"] -eq $null) {
Enable-SPFeature -Identity 0806d127-06e6-447a-980e-2e90b03101b8 -url $web.Url -Confirm:$false
} else {
Disable-SPFeature -Identity 0806d127-06e6-447a-980e-2e90b03101b8 -url $web.Url -Confirm:$false
}
}
}
}
Please note though that above script will work for small site collections. But for larger object hierarchies, you will need to include proper memory management (SPAssignment) to ensure proper release of memory.
As always, have fun coding.
How To – Deploy a SharePoint 2010 Visual Web Part
How To – Deploy a SharePoint 2010 Visual Web Part
Build the solution from Visual Studio 2010.
Package the solution.
Go to the Build menu and select Package.
Deploy solution to SharePoint server.
Browse to the directory which contains your webpart.wsp file. Copy this file to a local directory on the SharePoint server.
Log on to the SharePoint server and open the SharePoint 2010 Mangement Shell.
Run the following command: Add-SPSolution –LiteralPath .
Deploy solution to your SharePoint site.
Open SharePoint 2010 Central Administration
Browse to System Settings -> Manage farm solutions.
Click your webpart.wsp.
Click Deploy Solution.
Select the appropriate options and click OK.
Add the solution to the Web Part Gallery.
Browse to http://Server/_layouts/newdwp.aspx.
Select the checkbox next to your solution.
Click Populate Gallery.
Your web part should now show in the Gallery and be available for use on site pages.
Subscribe to:
Posts (Atom)