2012-03-30 49 views
0

我试图从运行Win2k3或Win2k8的服务器中删除非Microsoft MSP。在选择“查看已安装的更新”时,“更新”确实会显示在“添加/删除程序”中。不过,我似乎无法找到获取MSP GUID的方法。使用powershell删除非Windows MSP包

我计划使用

msiexec /i {GUID-OF-PRODUCT} MSIPATCHREMOVE={GUID_OF_PATCH} /qb 

这是在这篇文章中找到:how to remove the Patch from console

但是,我没有办法在命令行中获得补丁GUID。有没有人能够做到这样的事情?微软补丁有很多方法可以做到这一点,但由于这不是微软,我希望它仍然有可能。 谢谢, Greg

回答

0

您可以使用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

希望帮助, 亚伦

+0

工程。尽管没有足够的“声誉”来投票回答。 – gregs 2013-05-13 12:58:55