您可以使用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(即在“添加/删除程序”中显示的名称)。
$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);
要么你走,路线现在你只需要遍历$补丁和使用适当的参数从命令行调用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
希望帮助, 亚伦
工程。尽管没有足够的“声誉”来投票回答。 – gregs 2013-05-13 12:58:55