2012-03-30 48 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