Export/Import SharePoint 2010 solutions using PowerShell (Part 3/3)

This last part will contain a script that will deploy the solutions to all available web applications. So you should only use this script if the solutions that are not deployed, have to be deployed on all SharePoint 2010 Web Applications.
Alternitavely, you can also change the script to only deploy the solution to 1 or more Web Applications.

Just to make sure, I Added a “Warning box”, which will display the information described above for people who had no time to read the piece of information.

#This script will deploy all added solutions to all web applications
Add-PSSnapin Microsoft.SharePoint.PowerShell

function deploySolutions
    $Yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes"
    $No = New-Object System.Management.Automation.Host.ChoiceDescription "&No"
    $choices = [System.Management.Automation.Host.ChoiceDescription[]]($Yes,$No)
    $caption = ""
    $message = "Choosing YES will deploy ALL solutions available to ALL web applications, are you sure?"
    $result = $Host.UI.PromptForChoice($caption,$message,$choices,0)
    if($result -eq 0)
        Get-SPSolution | ForEach-Object {If ($_.ContainsWebApplicationResource -eq $False) {Install-SPSolution -Identity $_ -GACDeployment} else {Install-SPSolution -Identity $_ -AllWebApplications -GACDeployment}}
    elseif($result -eq 1)
        Write-Host "you chose not to deploy the solution, press any key to exit" -fore red
        $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")


The output of the above script will look similar to this:

Improvements for all scripts posted are very welcome!.

Happy scripting!

Leave a Reply

Your email address will not be published. Required fields are marked *