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"

Thursday, January 24, 2013

Extracting Solution Packages from SharePoint 2010 via PowerShell

There may come times when it becomes necessary to synchronize your SharePoint farms. In my experience, solution packages are virtual moving targets where developers apply changes willy-nilly. Thus, piecing together the contents of a solution package becomes a tedious and cumbersome task that distracts you from other time-sensitive projects.

Well, to speed up the process, you can use a shorthand approach by simply extracting the solution packages deployed to their respective content databases. How you ask? By way of Powershell. Here goes:
$solutions = [Microsoft.SharePoint.Administration.SPFarm]::Local.Solutions;

foreach ($solution in $solutions) {
        $solution.SolutionFile.SaveAs("c:\temp\packages\" + $solution.Name);
}