SharePoint 2007 shipped with the STSADM command-line tool which was meant to be used for all kind of administration tasks like installing and deploying Solutions. Although the STSADM is still available in SharePoint 2010 for backwards compatibility the recommended way is to use PowerShell instead. SharePoint 2010 ships with a great number of PowerShell cmdlets which simplify the process of administering your SharePoint Farm. And although PowerShell is way more powerful than STSADM, it adds some extra complexity.
Installing SharePoint Solutions with PowerShell – really a change for the better?
In case you forgot how things looked like in SharePoint 2007, you could install a Solution Package (WSP) using the following command:
stsadm -o addsolution -filename <wsp>
stsadm -o addsolution -filename Mavention.SharePoint.AudiencedPreview.wsp
In SharePoint 2010 using PowerShell you have to use the Add-SPSolution cmdlet instead:
Add-SPSolution -LiteralPath <wsp>
And here’s the catch: while STS was able to resolve the full path to the WSP file from the current location, the Add-SPSolution cmdlet requires you to provide the full path to the WSP file. If you try to provide only the name of the WSP file, all you’ll see is a File Not Found exception:
So in the scenario above I would have to type the following cmdlet to get the job done:
Add-SPSolution -LiteralPath C:\wma\Mavention.SharePoint.AudiencedPreview\Mavention.SharePoint.AudiencedPreview\bin\Release\Mavention.SharePoint.AudiencedPreview.wsp
Even if you can complete the path using TAB it’s still pretty annoying. Luckily there is a trick you can use to make this easier.
Installing SharePoint Solutions with PowerShell the easier way
One of the standard cmdlets provided with PowerShell is the Get-Location cmdlet which returns the current directory. PowerShell will also allow you to use its alias gl which makes it even easier to remember.
So in our scenario, in order to install the SharePoint Solution Package, all you have to type is:
Add-SPSolution -LiteralPath "$(gl)\Mavention.SharePoint.AudiencedPreview.wsp"
Looks way better, doesn’t it?
Technorati Tags: SharePoint 2010,PowerShell