Posted on:
Categories: SharePoint
Description:

Scenario

As a SharePoint Admin, one of the regular tasks we perform after patching is to validate that all components have been successfully patched. The recommended way is to utilizes STSADM.exe with the "-o localupgradestatus" parameter. There is no PowerShell equivalent for this command. This command will return a large XML file which needs to be reviewed for errors. This process is tedious and error prone as we have to manually look for a Status of Error.

Solution

We have written a script which will run the STSADM command mentioned above, but, will only return Objects which have an Error Status.

#-------------------------------------------------------------------------------------------
# Name:   Get-SPLocalUpgradeStatus
# Description:  This script will display objects which need to be upgraded
# Usage:  Run the function with the required parameters
# By:    Ivan Josipovic, softlanding.ca
#-------------------------------------------------------------------------------------------
Function Get-SPLocalUpgradeStatus (){
    Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction 0;
 $ErrorActionPreference = "Stop";
 
 $RawXML =  stsadm.exe -o localupgradestatus;
 $xml = [xml]($RawXML | Select-Object -First ($RawXML.Length - 6));
 $output = $xml.Objects.Object | ? {$_.Status -ne "OK"} | Format-List;
 if ($output) {
  $output
 } else {
  Write-Host -Foregroundcolor green "All is well!";
 }
}

Get-SPLocalUpgradeStatus;