2

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?

SPBeginer
  • 2,547
  • 14
  • 52
  • 88

2 Answers2

3

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
    }    
}
yandr
  • 1,305
  • 8
  • 11
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

Waqas Sarwar MVP
  • 57,008
  • 17
  • 43
  • 79
  • 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 04 '15 at 14:24