<CharlieDigital/> Programming, Politics, and uhh…pineapples

18Jul/11Off

Powershell, SharePoint Solutions, and Waiting for Deployment

When installing SharePoint solution packages using Powershell, you'll need to wait for the solution to be installed after calling install-spsolution before you can enable features using enable-spfeature.  As a part of an automated script, you'd like for the script to know when the install is finished before continuing.

It's surprisingly easy and can be accomplished with only a tiny bit of code:

$sln = add-spsolution [YOUR_SOLUTION_PATH_HERE]

install-spsolution -identity [YOUR_SOLUTION_NAME_HERE] -gacdeployment

while($sln.JobExists)
{
    echo "Deployment in progress..."

    start-sleep -s 5
}

That's it!

On uninstall, the process is a little bit different as uninstall-spsolution does not return an instance of the solution.  You will want to grab the solution before you start the retraction:

$sln = get-spsolution -identity [YOUR_SOLUTION_IDENTITY]

uninstall-spsolution -identity [YOUR_SOLUTION_IDENTITY] -confirm:$false -webapplication:$webAppName

echo "Started solution retraction..."

while($sln.JobExists)
{
	echo " > Uninstall in progress..."
	start-sleep -s 5
}

remove-spsolution -identity [YOUR_SOLUTION_IDENTITY] -confirm:$false

This helps make for a much smoother install and uninstall process as you can be more certain that your solution is installed before executing code dependent on the solution (feature activation, solution removal, etc).

Posted by Charles Chen

Filed under: SharePoint Comments Off