MANAGING SHAREPOINT 2010 FARM SOLUTIONS WITH WINDOWS POWERSHELL
In SharePoint 2007, you can manage solutions using the stsadm command. In SharePoint 2010, stsadm still works, but is deprecated in favor of PowerShell cmdlets. Whereas with stsadm you use a command-line switch to specify the operation to perform, with PowerShell you use separate cmdlets. Below are the list of stsadm commands and equivalent PowerShell commands for common tasks to manage a farm solution. SharePoint 2010 also includes support for sandbox solutions. While they are not discussed here, you’d use similar cmdlets to manage them as well.
When running a cmdlet, the cmdlet returns right away, but the operation will take some time to complete. If you attempt to execute one cmdlet immediately after another, you may get an error if the previous operation hasn’t finished running.
To get further information on a cmdlet, for instance add-spsolution, just type get-help add-spsolution in PowerShell.
Starting the SharePoint PowerShell You can find the SharePoint 2010 Management Shell under the Microsoft SharePoint 2010 Products program group. You should run it as the farm administrator account. Otherwise, you would get the following error:
The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.
This solution contains an assembly which must be registered in Web.config (as a SafeControl), so I use the -url switch with stsadm to specify the location of the desired Web application (to which Web.config belongs); alternatively, I could also use the -allcontenturls switch to deploy to all non-administrative web applications. With PowerShell, the -webapplication switch performs the same purpose.
With stsadm it’s also a good idea to run execadmsvcjobs to ensure that the operation is performed immediately. The cmdlet performs this step automatically.
As mentioned in the section Deploying solution, the solution requires modification to Web.config. With PowerShell, you must specify with the -webapplication switch the Web application from which the solution is to be retracted. Failure to do so will result in the following error:
Uninstall-SPSolution : This solution contains resources scoped for a Web application and must be retracted from one or more Web applications.
The cmdlet asks you to confirm the operation before proceeding. For a completely automated operation, you can turn off the confirmation with the -confirm switch.