Remember stsadm -o execadmsvcjob? Our rusty trust friend that allowed you to wait for a solution to retract or deploy before proceeding with the next command?
Well it’s dead in SP2010 and above. But fear not, here is a replacement for it -
1: function SPExecAdmSvcJobs([string]$solutionName)
2: { 3: $jobName = "*solution-deployment*$solutionName*"
4: $job = Get-SPTimerJob | ?{ $_.Name -like $jobName } 5: if ($job -eq $null)
6: { 7: Write-Host 'Timer job not found'
8: }
9: else
10: { 11: $jobName = $job.Name
12: Write-Host -NoNewLine "Waiting for .. $jobName"
13:
14: while ((Get-SPTimerJob $jobName) -ne $null)
15: { 16: Write-Host -NoNewLine .
17: Start-Sleep -Seconds 2
18: }
19: Write-Host "..Completed!"
20: }
21: }
So, how would you use the above? Easy!
1: UnInstall-SPSolution -Identity $solName -WebApplication http://spf2010 -Confirm:$false
2: SPExecAdmSvcJobs("$solName") 3: Remove-SPSolution -Identity $solName -Confirm:$false
4: Add-SPSolution -LiteralPath $solFileName -Confirm:$false
5: Install-SPSolution -Identity $solName -WebApplication http://spf2010 -GACDeployment -Confirm:$false
6: SPExecAdmSvcJobs($solName)
Or, you can also call WaitForJobToFinish with no parameters to wait for all jobs to finish.