Update solution, upgrade feature

03/04/2012 15:37

#input parameters

$siteUrl = "http://td_sp_dev1/sites/test"

$solutionsPath = "C:\GBP.Install\Upgrade"

function WaitForUpgrading($solutionName)

{

$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local

$isExecuted = $true

$solution = $null

foreach ($farmSolution in $farm.Solutions)

{

if ($farmSolution.Name.Equals($solutionName, [System.StringComparison]::InvariantCultureIgnoreCase))

{

$solution = $farmSolution

break;

}

}

 

if ($solution -ne $null)

{

write-host " " -nonewline

while ($solution.JobExists)

{

write-host "." -foreground green -nonewline

[System.Threading.Thread]::Sleep(2000)

}

 

write-host " "

$result = $solution.LastOperationResult

if ($result -ne [Microsoft.SharePoint.Administration.SPSolutionOperationResult]::DeploymentSucceeded -and

$result -ne [Microsoft.SharePoint.Administration.SPSolutionOperationResult]::DeploymentWarningsOccurred)

{

write-host "EXCEPTION:" $solutionName has been upgraded with ERRORS

}

else

{

write-host $solutionName has been successfully upgraded!

}

}

}

function UpgradeFeatures($featureId)

{

$featureGuid = New-Object System.Guid($featureId)

$features = $site.QueryFeatures($featureGuid, $true)

$type = $features.GetType()

 

foreach($feature in $features)

{

write-host " "

write-host Upgrading feature $featureId at $siteUrl -foreground green

$feature.Upgrade($false)

write-host Feature $feature.Definition.DisplayName has been successfully upgraded!

}

}

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction 'SilentlyContinue'

Start-SPAssignment -Global # This cmdlet takes care of the disposable objects to prevent memory leak.

#- Clear screen

cls

# update solutions

$solutions = @("Faq", "FaqWP", "Helpdesk", "MyRequisitions", "ResourcesGlobal", "SiteCollection", "WebServices")

foreach($solution in $solutions)

{

write-host Updating solution $solution -foreground green -nonewline

Update-spsolution -Identity ($solution + ".wsp") -LiteralPath ($solutionsPath + "\" + $solution + ".wsp") -GACDeployment

WaitForUpgrading ($solution + ".wsp")

write-host " "

}

 

# upgrade features

$site = Get-SPSite $siteUrl

$features = @("83221d53-4fb9-4d82-a4bd-425ed50b0362", "e1a28494-65dc-49a2-bf5a-229a0bbe5821")

foreach($feature in $features)

{

UpgradeFeatures $feature

}

 

 

write-host " "

write-host "Script finished."

write-host " "

Stop-SPAssignment -Global # This cmdlet takes care of the disposable objects to prevent memory leak.

Remove-PsSnapin Microsoft.SharePoint.Powershell