Thursday, 2 August 2012

Useful Powershell script to wait until solutions are deployed or retracted

After at last deciding to sort myself out with some Powershell scripts for automatically deploying or retracting solutions, I came across this one. It will wait for any scheduled jobs to complete on a WSP. I found it on Brian Cartmel's blog: http://sharepintblog.com/2011/06/13/wait-for-a-solution-to-deploy-with-powershell/

For reference, here's the script again:


## Get the solution 
$Solution = Get-SPSolution -identity $SolutionFileName
$lastStatus = ""
## loop whilst there is a Job attached to the Solution 
while ($Solution.JobExists -eq $True) 

    $currentStatus = $Solution.JobStatus 
    if ($currentStatus -ne $lastStatus) 
    { 
            Write-Host "$currentStatus…" -foreground green -nonewline 
            $lastStatus = $currentStatus 
    } 
    Write-Host "." -foreground green -nonewline 
    sleep 1 

## completed 
Write-Host "" 
Write-Host "     " $Solution.LastOperationDetails -foreground green

No comments:

Post a Comment