Peter Hinchley

Learning in Public

✪ Extract Installed Microsoft Office Updates from a Computer using PowerShell

I've lost count of how many times I have used the script referenced in this article to extract the Microsoft Office updates installed on a computer. I install Microsoft Office, connect the computer to the internet, use Windows Update to install all available software updates, and then use the script to extract those updates into a folder. These updates can then be copied into the Updates folder of the Microsoft Office installation media, thereby ensuring that the updates will be automatically installed when the media is next used to install Office. It's a great way of keeping the media up to date when installing Office during a reference image deployment of Microsoft Windows.

Anyway, I thought it would be cool to port the script to PowerShell. This is the code. The functionality is unchanged.

$updates = "{0}\updates" -f $env:temp
if (test-path $updates) { ri $updates -r -fo }; md $updates | out-null
$msi = new-object -comobject windowsinstaller.installer
$msi.patchesex('', '', 4, 1) | %{
  $pkg = $_.patchproperty('LocalPackage')
  $msp = $msi.opendatabase($pkg, 32)
  if ($msi.summaryinformation($pkg).property(7) -match '000-0000000ff1ce}') {
    try {$view = $msp.openview("SELECT `Property`,`Value` FROM MsiPatchMetadata WHERE `Property`='StdPackageName'")} catch { return }
    $view.execute()
    $record = $view.fetch()
    copy-item $pkg ("{0}\{1}" -f $updates, $record.stringdata(2)) -force
  }
}
start $updates