Powershell and SP2010 (2) – Installing a solution

After reading this blogpost: WaitForWSPJob tool by MIchel Barneveld i had an idea, in SP2010 we can use Powershell to do the waiting because we can access the OM directly.

$file = Get-ChildItem $solution
$solutionID = $file.Name;

$farm = Get-SPFarm

$sol = $farm.Solutions[$solutionID]

if($sol){

   Write-Host -f Green "Going to uninstall $solutionID"

   if( $sol.Deployed -eq $TRUE ) {

        if ( $url -eq $null ) {
            Uninstall-SPSolution -Identity $solutionID -Confirm:0
        }
        else {
            Uninstall-SPSolution -Identity $solutionID -Confirm:0 -Webapplication $url
        }

        while( $sol.JobExists ) {
            Write-Host " waiting for retraction."
            sleep 1
        }
    }

    Write-Host -f Green "Going to Remove $solutionID"
    Remove-SPSolution -Identity $solutionID -Force -Confirm:0

    Write-Host -f red $solutionID is deleted from this Farm
}

The script will wait for any execution jobs:

Download the powershell script solution.ps1
Update (newer version) :
Download the powershell script solution.ps1

Some more powershell

Advertisements

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


%d bloggers like this: