Install Missing Updates Powershell Right Click Tool for Config Mgr 2012

Consider the following 2 scenarios:

1. You have ConfigMgr configured to make Windows Updates available to a computer, but do not force the installation.  You want to force the installation remotely through the console, rather than through Software Center on the computer.

OR

2. You have a computer which has updates waiting in a failed state, they will retry every week but you want to force the retry remotely rather than through Software Center on the computer.

The following code is based off of the ConfigMgr 2012 – Powershell RightClick tools available at:http://psrightclicktools.codeplex.com/ , and was originally posted as a forum post at: http://psrightclicktools.codeplex.com/discussions/449341

The following script should be referenced in an XML file located in the following subfolders of your console installation:
\XmlStorage\Extensions\Actions\ed9dee86-eadd-4ac8-82a1-7234a4646e62
\XmlStorage\Extensions\Actions\3514f0ab-7d2a-41c6-a344-4d49edce9a52
\XmlStorage\Extensions\Actions\3fd01cd1-9e01-461e-92cd-94866b8d1f39
After installing the ConfigMgr 2012 – Powershell RightClick tools (link above) you’ll have some examples in these directories to use as examples. Note: Since the console will not open powershell scripts, you’ll need to create a VBS script to act as a proxy to kick off your powershell script. (see the silentopenps.vbs file in the install directory of your ConfigMgr 2012 – Powershell RightClick tools for an example)

#Get Arguments
$ResourceID = $args[0]
$Server = $args[1]
$Namespace = $args[2]

$strQuery = "Select ResourceID,ResourceNames from SMS_R_System where ResourceID='$ResourceID'"
Get-WmiObject -Query $strQuery -Namespace $Namespace -ComputerName $Server | ForEach-Object {$CompName = $_.ResourceNames[0]}

$objpopup = new-object -comobject wscript.shell

If (test-connection -computername $CompName -count 1 -quiet){
	$Error.Clear()
	$MissingUpdates = @(Get-WmiObject -ComputerName $CompName -Class CCM_SoftwareUpdate -Filter ComplianceState=0 -Namespace root\CCM\ClientSDK | Foreach-Object {[WMI]$_.__PATH})
	$returncode = Invoke-WmiMethod -ComputerName $CompName -Class CCM_SoftwareUpdatesManager -Name InstallUpdates -ArgumentList (,$MissingUpdates) -Namespace root\ccm\ClientSDK
	if($returncode.ReturnValue -eq 0){
		$actualpopup = $objpopup.popup("Software Update installation successfully triggered on $CompName",0,”Results”,0)
	}else{
		$errorcode = $returncode.ReturnValue
		$actualpopup = $objpopup.popup("Software Update installation returned code: $errorcode on $CompName",0,”Results”,16)
	}
}
else {$actualpopup = $objpopup.popup(“$CompName is not on“,0,”Results”,16)}

Sample XML (untested):

<ActionDescription Class="Group" DisplayName="My Custom RightClick Client Tools" MnemonicDisplayName="My Custom RightClick Client Tools" Description="My Custom RightClick Client Tools" SqmDataPoint="53">
	<ShowOn>
		<string>DefaultHomeTab</string>
		<string>ContextMenu</string>	
	</ShowOn>
	<ResourceAssembly>
		<Assembly>AdminUI.CollectionProperty.dll</Assembly>
			<Type>Microsoft.ConfigurationManagement.AdminConsole.CollectionProperty.Properties.Resources.resources</Type>
	</ResourceAssembly>
	<ActionGroups> 
		<ActionDescription Class="Executable" DisplayName="Install Missing Windows Updates" MnemonicDisplayName="Install Missing Windows Updates" Description="Installs Missing Windows Updates">
			<ShowOn>
				<string>ContextMenu</string>
				<string>DefaultHomeTab</string>
			</ShowOn>
			<Executable>
				<FilePath>"wscript.exe"</FilePath>
				<Parameters>"C:\PathtoVBS\SilentOpenPS.vbs" "C:\PathtoScript\Client - Install Missing Updates.ps1" ##SUB:ResourceID## "##SUB:__Server##" "##SUB:__Namespace##" </Parameters>
			</Executable>
		</ActionDescription>
  </ActionGroups>
</ActionDescription>

-Matthew DeBoer

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s