1

I have added and installed couple of .wsp solutions to farm using following commands:

$getSolution = Get-SPSolution -Identity "MySolution.wsp"
if($getSolution -eq $null)
{
Add-SPSolution -LiteralPath "Path\MySolution.wsp"
}
if($getSolution.Deployed -eq $false )
{
Install-SPSolution –Identity MySolution.wsp -GACDeployment
}

As above command will take some time to fully deployed the solution from status deploying to deployed. I want to move forward in the script only if the status of solution is deployed. How can i check this using powershell?

2

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.

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
}

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

  • Thats fine! this script will return only true or false if solution status is deployed or not. i want to move forward only if status is deployed. Some solutions take long time to deployed. eventually this function will return false if the status of solution is deploying. i only want the remaining part of script to run if status is deployed. How can i periodically check this? – SPBeginer Apr 4 '15 at 14:24
2

You need something like the following:

$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
    }    
}
  • This is correct, elegant, and overall beautiful solution for taking into account the Deploying status. – Jussi Palo Nov 24 '16 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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