Automating Installation and Uninstallation for SharePoint 2010 Farm Solution

I’ve been trying to figure out how to automate the process for uninstalling a farm solution in SharePoint 2010. This is a two-step process:

  1. Retract the solution from the farm
  2. Remove it from the solution store

Unfortunately, you can’t perform the second operation right after the first, because there’s a delay when SharePoint retracts a solution. The delay can be several seconds, so you can either wait, or do something else while remembering to perform the second step.

Similarly, when installing a farm solution, you must first add it to the solution store before deploying it. Deployment can also take several seconds. In this case the delay is less inconvenient because you can let it run and work on something else, but it’d be nice to know when deployment completes.

Here are some PowerShell scripts which automate the process. The installation script keeps checking until it determines that the solution is retracted, at which time it proceeds to remove the solution from the store. The uninstallation script does its work then tells you when the solution is removed from the solution store.

To run:

  1. Start SharePoint 2010 Management Shell as administrator
  2. Unzip the attached archive
  3. Edit globals.ps1 to enter values for your environment
  4. Run either install.ps1 or uninstall.ps1

I’m new to PowerShell so suggestions would be welcome.


Further Reading:

  • Ted Pattison has a great overview of using PowerShell to install, retract and remove solutions from a SharePoint farm
  • And Gary LaPointe wrote a very useful PowerShell script for deploying all SP2010 solution packages


Related posts: