Nowadays I’m working on a SharePoint deployment project using Advanced Installer, AutoSPInstaller and custom PowerShell scripts. One of that script deploys a set of solution packages in a given order. Order is important if you have dependencies between the solutions. So I defined the name of the solutions and the order of them in a xml file. In this post I’d like to share that script and xml.
param ( [string]$WebApplicationUrl = "" ) Remove-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue Function Pause($action) { Write-Host "Press any key to $action..." $null = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") } Function WriteLine { Write-Host -ForegroundColor White "--------------------------------------------------------------" } Function WaitForInsallation([string] $Name) { Write-Host -NoNewline "Waiting for deployment job to complete" $Name "." $wspSol = get-SpSolution $Name while($wspSol.JobExists) { sleep 2 Write-Host -NoNewline "." $wspSol = get-SpSolution $Name } Write-Host "" Write-Host -ForegroundColor green "Deployment job is finished" WriteLine } $Host.UI.RawUI.WindowTitle = " -- Deployment of AIP Solution Packages --" $0 = $myInvocation.MyCommand.Definition $env:dp0 = [System.IO.Path]::GetDirectoryName($0) $bits = Get-Item $env:dp0 | Split-Path -Parent $wspPath = "$bits\packages" $configFile = "$wspPath\SolutionDeployConfig.xml" If (!([string]::IsNullOrEmpty($WebApplicationUrl))) { If (Test-Path -Path $configFile) { [xml]$xmlinput = (Get-Content $configFile) ForEach ($solution in $xmlinput.Solutions.Solution) { $identity = $solution.getAttribute("Identity") $webApplication = $solution.getAttribute("WebApplication") Write-Host -ForegroundColor Blue "Deploying solution: $identity" $wsp = Get-SPSolution | Where{$_.Name -eq $identity} if($wsp -eq $null) { Write-Host "Adding solution" Add-SPSolution -LiteralPath ($wspPath + "\" + $identity) } else { Write-Host "Solution already exists" if($wsp.Deployed -eq $true) { Write-Host "solution is deployed already, updating the solution" Update-SPSolution -identity $wsp.SolutionId -LiteralPath ($wspPath + "\" + $identity) -GACDeployment } else { Write-Host "Removing solution" Remove-SPSolution -identity $wsp.SolutionId -confirm:$false Write-Host "Adding solution" Add-SPSolution -LiteralPath ($wspPath + "\" + $identity) } WaitForInsallation -Name $wsp.Name } $wsp = Get-SPSolution | Where {$_.Name -eq $identity} if($wsp -ne $null) { Write-Host "Installing solution" if ($webApplication) { Install-SPSolution -identity $wsp.SolutionId -WebApplication $WebApplicationUrl -GACDeployment -force } Else { Install-SPSolution -identity $wsp.SolutionId -GACDeployment -force } } WaitForInsallation -Name $wsp.Name } WriteLine Write-Host -ForegroundColor Blue "Deployment is completed" WriteLine Pause "exit" } Else { Throw " - Cannot locate solution deployment configuration file; please check that the SolutionDeployConfig.xml file is in the \packages subfolder." } } Else { Throw " - Please provide the web application url parameter -WebApplicationUrl" }
And the following xml is the configuration file of the deployment. It contains the packages to be deployed. Script will deploy them in the order of definition. I used WebApplication atrribute to specify if that solution will be deployed to a specific web application (url is set by powershell script parameter) or not.
<?xml version="1.0" ?> <Solutions> <Solution Identity="logging.wsp" /> <Solution Identity="webconfigmodifications.wsp" /> <Solution Identity="configuration.wsp" /> <Solution Identity="copysitecollection.wsp" /> <Solution Identity="branding.wsp" /> <Solution Identity="webparts.wsp" WebApplication="true" /> <Solution Identity="search.wsp" WebApplication="true" /> </Solutions>
Hope this helps in your deployment tasks…
3 thoughts on “Batch Solution Deploy using PowerShell”
Thanks for sharing. I would like to ask you for more details on how did you integrate the above code with Advanced installler. what you are doing here is exactlly what I want to accomplish with sharepoint and advanced installer. One more question , which licence of adanced installer are you using ?
Thanks for you help in advance
Let me briefly explain the steps. First of all, the setup of the sharepoint, office web apps (with prerequisites, service packs and hot fixes) is prepared by autospintall project. After that I wrote PowerShell scripts for the customizations on the SharePoint such as site coll. restores, solution deploys etc. At this point I have a bat file and a bunch of powershell scripts for SharePoint installation and my custom PowerShell scripts for the customizations. My purpose was to coordinate these seperate installation files into one msi package. So I used Advanced Installer to run these bat and ps1 files synchronously. We had some problems to run ps1 files via custom actions so we prepared a bat file for each ps1 file as a workaround and run that bat files as custom actions. Alternative paths can also be defined for upgrade or maintanance modes which I haven’t done yet. I hope these helps. Actually I’m planning to write a detailed post about the integration between Advanced Installer & AutoSPInstall with screenshots.
Thanks for your reply Kerem.
Actualy what I have now is a batch file for every powershell as you metioned above, I used them before to run it from command line for manual installation. The batch is only used to bring up the powershell script. I added powershell as a prerequisite, too in advanced installer.
I added the batch file in a custom action and added both the batch and powershell as temproray fie in the windows temprory directory, it did bring up the powershell file but I still need to do some tweaking in the batch file to pass location of package “.wsp” and some parameter settings from the advanced installer.
Thanks again for your help.