您可以使用 Windows Installer com 对象来枚举补丁。
查看这篇文章。它并不能完全满足您的需求,但它提供了您需要的 comObject.types.ps1xml 文件:
http://www.snowland.se/2010/02/21/read-msi-information-with-powershell/
那么你可以这样做来获取补丁:
$installer_obj = New-Object -com WindowsInstaller.Installer;
$patches = $installer_obj.InvokeParamProperty("PatchesEx", "Product-Code-GUID", "s-1-1-0", 7, 15);
Product-Code-GUID 是您感兴趣的产品的 GUID。我更喜欢枚举产品列表,并根据人类可读的名称以编程方式获取 GUID(即显示在 Add /删除程序)。
$installer_obj = New-Object -com WindowsInstaller.Installer;
$all_products = $installer_obj.GetProperty("Products");
foreach($product_code in $all_products) {
$product_name = $installer_obj.InvokeParamProperty("ProductInfo", $product_code, "ProductName")
if($product_name -eq "MySQL Server 5.1") {
$interesting_product_code = $product_code;
}
}
$patches = $installer_obj.InvokeParamProperty("PatchesEx", $interesting_product_code, "s-1-1-0", 7, 15);
无论您采用哪种方式,现在您只需要遍历 $patches 并使用适当的参数从命令行调用 msiexec(如果您选择对 $interesting_product_code 使用文字字符串,只需替换变量和连接使用文字字符串 GUID。):
foreach($patch in $patches) {
$patch_code = $patch.GetProperty("PatchCode");
$argument_list = "/I" + $interesting_product_code + " MSIPATCHREMOVE=$patch_code /qb /norestart";
Start-Process -FilePath "msiexec.exe" -ArgumentList $argument_list -Wait;
}
这是对 Windows Installer com 对象的引用。你也可以用它做一些其他有趣的事情:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa369432%28v=vs.85%29.aspx
希望对您有所帮助,
亚伦