Home > PowerShell, SharePoint, SharePoint 2010 > SharePoint 2010: PowerShell Scripts to Check Deployment Status of WSP Solutions

SharePoint 2010: PowerShell Scripts to Check Deployment Status of WSP Solutions


Following on again from my last post (SharePoint 2010: PowerShell to Wait for WSP Solution Deployment Timer Job to Complete), here are a couple more useful scripts that check the deployment status of a WSP solution.

The function “GetSPSolutionIsDeployed” checks whether a solution is deployed, and optionally whether it is deployed to a specific web application, returning true if it is deployed. Call the function with the WSP solution filename (without the path but including the file extension), and if you want it to check if it is deployed to a specific web application, also pass in the URL of the web application.

function GetSPSolutionIsDeployed([string]$solutionName, [string]$webApplicationUrl)
{
	# Get the solution
$solution = Get-SPSolution -Identity $solutionName -ErrorAction SilentlyContinue
if (-not($solution))
	{
		Write-Host "Unable to find solution '$solutionName'."
		return $false
	}

# If a web application Url was not specified then simply return the value of the Deployed property
if (-not($webApplicationUrl))
	{
		return $solution.Deployed
	}

# As a web application Url was specified, get the web application and check whether the solution has been deployed to it
$webApplication = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($webApplicationUrl)
if (-not($webApplication))
	{
		Write-Host "Unable to find web application '$webApplicationUrl'."
		return $false
	}

	# Check whether the solution has been deployed to the web application
foreach ($deployedWebApplication in $solution.DeployedWebApplications)
	{
		if ($webApplication.Id -eq $deployedWebApplication.Id)
		{
			return $true
		}
	}

	return $false
}

The function “GetSPSolutionLastDeploymentSucceeded” is useful to find out whether the last solution deployment succeeded and to output the last operation details which includes error information if there was a failure. I used to have to go into Central Admin every time a solution failed to find out the cause, which was often a locked file for example, and that was quite time-consuming, so figured it would be useful to output this in the deployment scripts. To use it, just pass in the WSP solution filename as with the other function, and it will return true if the last operation succeeded, while outputting the reason for failure when it returns false.

function GetSPSolutionLastDeploymentSucceeded([string]$solutionName)
{
	# Get the solution again to make sure all deployment info is up-to-date
$solution = Get-SPSolution -Identity $solutionName -ErrorAction SilentlyContinue
if (-not($solution))
	{
		Write-Host "Unable to find solution '$solutionName'." -ForegroundColor Red
		return $false
	}

	# Check the solution deployment's last operation result was successful
$lastOperationResult = $solution.LastOperationResult
if ($lastOperationResult -eq [Microsoft.SharePoint.Administration.SPSolutionOperationResult]::DeploymentSucceeded)
	{
		Write-Host "Solution '$solutionName' last deployment succeeded."
		return $true
	}

$lastOperationDetails = $solution.LastOperationDetails
	Write-Host "Solution '$solutionName' last operation result is '$lastOperationResult'." -ForegroundColor Red
Write-Host "Details: $lastOperationDetails" -ForegroundColor Red

	return $false
}
About these ads
  1. June 20, 2012 at 13:59

    Thanks Nick, this post helped a lot, especially the part regarding LastOperationDetails. Thanks again, James.

  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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: