【问题标题】:Remove non-windows MSP packages with powershell使用 powershell 删除非 Windows MSP 包
【发布时间】:2012-03-30 14:58:07
【问题描述】:

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

我打算用

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

在这篇文章中发现:how to remove the Patch from console

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

【问题讨论】:

    标签: powershell patch updates


    【解决方案1】:

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

    希望对您有所帮助, 亚伦

    【讨论】:

    • 那行得通。但是没有足够的“声誉”来投票给答案。
    猜你喜欢
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多