Friday, June 15, 2012

Powershell script to wait for Job to finish

When you deploy the sharepoint solution using powershell script it will always says that the solution is not yet deployed kind of issues.

This is the place where we need to wait for the next operation to complete the previous one.

Here is the code sample for the same :

function WaitForJobToFinish([string]$SolutionName1)
    $JobName = "*solution-deployment*$SolutionName1*"
    $job = Get-SPTimerJob | ?{ $_.Name -like $JobName }
    if ($job -eq $null) 
        Write-Host 'Timer job not found'
        $JobFullName = $job.Name
        Write-Host -NoNewLine "Waiting to finish job $JobFullName"
        while ((Get-SPTimerJob $JobFullName) -ne $null) 
            Write-Host -NoNewLine .
            Start-Sleep -Seconds 2
        Write-Host  "Finished waiting for job.."

No comments:

Post a Comment