6

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.

6 Answers 6

6

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)
12

You can tell the status of a deployment by observing the 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 retracted!

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
    }

}
1
  • Hey shufler, thanks for you post here. I'm in a bad situation where solution management shows "Deployed", but $s.JobExists returns $true all the time so I can't update my solution anymore. I can however remove and install the solution from scratch every time. I've cleared the sharepoint config cache, restarted everything, but got nowhere. Any ideas?
    – Andreas
    Aug 3, 2021 at 21:28
5

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.

5

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
2
  • Why do you overwrite $solution in the while loop?
    – soniiic
    Jul 9, 2015 at 14:00
  • 1
    Wildy late with this reply, but it's checking the JobExists property every second to wait for the deploy to finish. So it refreshes the object to check the property each time. Dec 7, 2015 at 1:03
0

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

0

You can get a status from the solution's job is about as close as you can get to a real status.

$solutionName = '<your_wsp_name.wsp>'    
$solution = Get-SPSolution -Identity $solutionName -ErrorAction SilentlyContinue  
[string]$jobStatus = $solution.JobStatus

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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