Wednesday, January 30, 2013

Universal PowerShell Script to Deploy SharePoint Solution Packages

So, I was tasked with deploying several solution packages to an SharePoint 2010 alpha environment. Obviously, task one was to gather all the packages to be deployed. Task two was going to turn into a tedious headache until I ventured off into the PowerShell scripting world. What resulted was a universal script that I could use going forward that would deploy any number of wsp files. Below follows the script that handles said deployment.

A couple of things to note:
   1. This script assumes that a ps1 script is generated and is included in the folder from which your WSPs will be deployed.
   2. You have access to a SharePoint server on the farm.


Set-ExecutionPolicy Unrestricted 


$fc = new-object -com scripting.filesystemobject
$curFolder = Split-Path ($MyInvocation.MyCommand.Path)
$folder = $fc.getfolder($curFolder)

foreach ($i in $folder.files) {
  IF ($i.name -like "*.wsp")
  {
    $fullPath = join-path $curFolder $i.name
    Add-SPSolution $fullPath
    Install-SPSolution -Identity $i.name -GACDeployment
  }
}


Write-host "SharePoint 2010 Solutions Have Been Deployed to the Farm"
Write-host "Review Central Administration For Accuracy"

No comments:

Post a Comment