Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am Looking for a way to detect if the a solution is deploying the following code does not seem to return "Deploying" like I see in central admin.

$wspID = Get-SPSolution -Identity 'mysolution.wsp';
Write-Host $wspID.Status;

running the above code repeatedly while deploying or retracting never returns "deploying" only things like "NotDeployed","GlobalDeployed", etc.

I want to determine it's deploying state so my code will wait until the previous solution is deployed.

share|improve this question

5 Answers 5

up vote 4 down vote accepted

There is no way to detect the deploy*ing* state of a solution, but you can check if the solution is deploy*ed*:

if($wspID.Deployed -eq $true){
}

If Deployed returns false wait a couple of seconds and try again.

share|improve this answer

The best solution is to use the SPSolution.LastOperationResult and SPSolution.LastOperationDetails properties.

$solution = Get-SPSolution -Identity:$file
while ($solution.JobExists -eq $true) {
    Write-Host '.' -NoNewline
    sleep -Seconds:1
    $solution = Get-SPSolution -Identity:$file
}
$lastOperationResult = $solution.LastOperationResult
return ($lastOperationResult -eq [Microsoft.SharePoint.Administration.SPSolutionOperationResult]::DeploymentSucceeded)
share|improve this answer

The status only gives you basic info, but you can see what's going on by looking at the JobExists property, here's a but of a script doing that as part of a scripted deployment ($file is the wsp name)

$solution = Get-SPSolution -Identity:$file
while ($solution.JobExists -eq $true) {
    Write-Host '.' -NoNewline
    sleep -Seconds:1
    $solution = Get-SPSolution -Identity:$file
}
Write-Host
share|improve this answer

You can tell the status of a deployment by observing combined values of the Deployed and JobExists properties of the SPSolution object.

SPSolution.Deployed
True - Solution is deployed
False - Solution is not deployed

SPSolution.JobExists
True - A retract/deploy job exists for this solution.
False - No job

It's important to check both of these properties because depending on their state, the solution might not be "seen" as deployed by follow-up actions:

Deployed | JobExists | Is it really deployed?
---------------------------------------------
  False  |   False   | No.
  False  |   True    | No. But it's being deployed!
  True   |   False   | Yes.
  True   |   True    | No. The job hasn't yet cleaned up and can block other actions

(I don't like using the SPSolution.JobStatus property because it can be $null even though SPRunningJobStatus should have a value.)

Tying this all together, I use an algorithm similar to this to check on the status of a deployment:

$solution = "example.wsp"
Install-SPSolution -Identity $solution

$deployed = $False
while ($deployed -eq $False) {
    sleep -s 5
    $s = Get-SPSolution -Identity $solution
    if ($s.Deployed -eq $True -And $s.JobExists -eq $False) {
        $deployed = $True
    }

}

For retracting a solution the logic changes a bit:

Deployed | JobExists | Is it really retracted?
---------------------------------------------
  False  |   False   | Yes.
  False  |   True    | No. The job hasn't yet cleaned up and can block other actions!
  True   |   False   | No.
  True   |   True    | No. But it's being deployed!

And in code:

$solution = "example.wsp"
Uninstall-SPSolution -Identity $solution

$deployed = $True
while ($deployed -eq $True) {
    sleep -s 5
    $s = Get-SPSolution -Identity $solution
    if ($s.Deployed -eq $False -And $s.JobExists -eq $False) {
        $deployed = $False
    }

}
share|improve this answer

Sharepoint creates job rather than deploy immediately, so you should check if the job has executed successfully. Take a look at this.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.