Pete Hinchley: Extract Installed Microsoft Office Updates from a Computer using PowerShell

I've lost count of how many times I have needed 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 shown below 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.

$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