stsadm -o execadmsvcjobs replacement for SharePoint 2010

Posted on 5/7/2012 @ 6:30 AM in #SharePoint by | Feedback | 3788 views

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.

Sound off but keep it civil:

Older comments..


On 5/6/2012 12:19:56 PM Rob Garrett said ..
I believe it's still available in SP2010. MS are pushing Powershell but STSADM is still supported.

R


On 5/6/2012 4:12:53 PM Fred Morrison said ..
Is it safe to assume that everywhere in your example where you wrote:


WaitForJobToFinish($solName)


you really meant to write:


SPExecAdmSvcJobs($solName)


to match the name of the function you created earlier in the article?


On 5/7/2012 6:31:28 AM Sahil malik said ..
Rob - Yep, but execadmsvcjobs is out! :) even with stsadm.


Fred - yup, you're right. Fixed. Thanks!


On 5/15/2012 3:29:54 PM Rob Garrett said ..
Huh? I use execadmsvcjobs all the time in SP2010, the command is definitely there. Are you suggesting that it doesn't work, or that the command is missing?

R.


On 5/15/2012 3:33:51 PM Rob Garrett said ..
Ah I see, all jobs run in in the timer service. The command still exists but doesn't do anything.