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:
1 2 3 4 5 6 7 8 9 10 |
$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:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$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).
1 Response
[…] Powershell, SharePoint Solutions, and Waiting for Deployment […]