Powershell and SP2010 (2) – Installing a solution

By | 2010-04-06

After reading this blogpost: WaitForWSPJob tool by MIchel Barneveld i had an idea, in SP2010 we can use Powershell to do the waiting because we can access the OM directly.

$file = Get-ChildItem $solution
$solutionID = $file.Name;

$farm = Get-SPFarm

$sol = $farm.Solutions[$solutionID]


   Write-Host -f Green "Going to uninstall $solutionID"

   if( $sol.Deployed -eq $TRUE ) {

        if ( $url -eq $null ) {
            Uninstall-SPSolution -Identity $solutionID -Confirm:0
        else {
            Uninstall-SPSolution -Identity $solutionID -Confirm:0 -Webapplication $url

        while( $sol.JobExists ) {
            Write-Host " waiting for retraction."
            sleep 1

    Write-Host -f Green "Going to Remove $solutionID"
    Remove-SPSolution -Identity $solutionID -Force -Confirm:0

    Write-Host -f red $solutionID is deleted from this Farm

The script will wait for any execution jobs:

Download the powershell script solution.ps1
Update (newer version) :
Download the powershell script solution.ps1

Some more powershell

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.