Wednesday, July 10, 2013

How to update SharePoint solutions?

Here is a PowerShell script for updating and deploying already installed wsp solution in a SharePoint farm.

Normally when you run Update-SPSolution SharePoint adds the solution to be updated to a queue and a installation/deployment job will take care of the actual installation. Before the timerjob runs there might be a few seconds delay, as for while the timerjob is running and performing the actual deployment of the newly updated solution.

I came up with the following script to check if the deployment is finished or still running. It doesn't return the prompt before it is done installing all solution located inside of a user specified directory, $packages_folder.

$packages_folder = "packages"

$local_path = $(get-location)
$packages = [IO.Directory]::GetFiles("$local_path\$packages_folder"); 

write-host "Installing:"
foreach ($package in $packages) {
 $package_withoutPath = $package.split('\')[-1];
 $wspID = Get-SPSolution -Identity $package_withoutPath;
 
 #wait here until the previously deployed package is finished with deployment
 write-host " $package_withoutPath" -nonewline;
 while($wspID.JobExists -eq $true) {
  write-host '.' -nonewline;
  sleep -Seconds:1;
 }
 write-host '';
 Update-SPSolution -Identity $package_withoutPath -LiteralPath $package -GACDeployment;
 
}

write-host "Finishing:"
foreach ($package in $packages) {
 $package_withoutPath = $package.split('\')[-1]
 write-host " $package_withoutPath" -nonewline;
 $wspID = Get-SPSolution -Identity $package_withoutPath;
 while($wspID.JobExists -eq $true) {
  write-host '.' -nonewline;
  sleep -Seconds:1;
 }
 write-host '';
}

The script loops over all packages found from a certain directory and updates them using the Update-SPSolution cmdlet.

Once all packages are added to the update queue, it waits for all deployment jobs to finish before returning the prompt.

No comments:

Post a Comment