Home > PowerShell, SharePoint, SharePoint 2010 > SharePoint 2010: PowerShell to Wait for WSP Solution Deployment Timer Job to Complete

SharePoint 2010: PowerShell to Wait for WSP Solution Deployment Timer Job to Complete

Following on from my post “SharePoint 2010: PowerShell to wait for Web.Config Modifications One-Time Timer Job to Complete“, here is another useful PowerShell script that waits for a WSP Solution install or uninstall to complete, as that too runs asynchronously.

PowerShell scripts cannot simply deploy a WSP solution then immediately afterwards activate a feature deployed by it, as the chances are that the WSP solution will not have completed installing so the feature will be unavailable. I have seen many scripts where people simply add a sleep for a few seconds and hope that will be enough. On a multi-server farm environment, WSP solution deployments take much longer than on single server or stand-along environments, as the deployments have to execute on each front-end web server to drop files into the 14 hive of each server.

To have a reliable deployment, especially when deploying lots of solutions, the script really should wait until the timer job for each WSP solution is complete, whether that be for install or uninstall, before proceeding with the rest of the script.

To use this PowerShell function, simply call it with the filename (without path) of the WSP solution file. It will output progress as it waits for it to complete as it can take a while depending on the complexity of the solution, and will return true or false to indicate whether the deployment was successful.

function WaitForSPSolutionJobToComplete([string]$solutionName)
	$solution = Get-SPSolution -Identity $solutionName -ErrorAction SilentlyContinue

	if ($solution)
		if ($solution.JobExists)
			Write-Host -NoNewLine "Waiting for timer job to complete for solution '$solutionName'."
		# Check if there is a timer job still associated with this solution and wait until it has finished
		while ($solution.JobExists)
			$jobStatus = $solution.JobStatus
			# If the timer job succeeded then proceed
			if ($jobStatus -eq [Microsoft.SharePoint.Administration.SPRunningJobStatus]::Succeeded)
				Write-Host "Solution '$solutionName' timer job suceeded"
				return $true
			# If the timer job failed or was aborted then fail
			if ($jobStatus -eq [Microsoft.SharePoint.Administration.SPRunningJobStatus]::Aborted -or
				$jobStatus -eq [Microsoft.SharePoint.Administration.SPRunningJobStatus]::Failed)
				Write-Host "Solution '$solutionName' has timer job status '$jobStatus'."
				return $false
			# Otherwise wait for the timer job to finish
			Write-Host -NoNewLine "."
			Sleep 1
		# Write a new line to the end of the '.....'
	return $true
About these ads
  1. George
    May 16, 2012 at 05:10 | #1

    Thanks for sharing, it’s a useful method

  2. Anil Kumar Kuchi
    July 9, 2012 at 16:41 | #2

    Thanks a lot …Its a very useful method..

  3. Wes
    September 19, 2012 at 17:07 | #3

    Thanks, just what I was looking for and didn’t have to do it myself.

  4. October 24, 2012 at 16:17 | #4

    Thanks a lot.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: