简体   繁体   English

PowerShell:如何查找和卸载MS Office Update

[英]PowerShell: How to find and uninstall a MS Office Update

I've been hunting for a clean way to uninstall an MSOffice security update on a large number of workstations. 我一直在寻找一种干净的方法来卸载大量工作站上的MSOffice安全更新。 I've found some awkward solutions, but nothing as clean or general like using PowerShell and get-wmiobject with Win32_QuickFixEngineering and the .Uninstall method on the resulting object. 我发现了一些尴尬的解决方案,但没有像使用PowerShell和get-wmiobject一样使用Win32_QuickFixEngineering和结果对象上的.Uninstall方法。

[Apparently, Win32_QuickFixEngineering only refers to Windows patches. [显然,Win32_QuickFixEngineering仅指Windows补丁。 See: http://social.technet.microsoft.com/Forums/en/winserverpowershell/thread/93cc0731-5a99-4698-b1d4-8476b3140aa3 ] 请参阅: http//social.technet.microsoft.com/Forums/en/winserverpowershell/thread/93cc0731-5a99-4698-b1d4-8476b3140aa3 ]

Question 1: Is there no way to use get-wmiobject to find MSOffice updates? 问题1:有没有办法使用get-wmiobject来查找MSOffice更新? There are so many classes and namespaces, I have to wonder. 有很多类和名称空间,我不得不怀疑。

This particualar Office update (KB978382) can be found in the registry here (for Office Ultimate): 可以在此处的注册表中找到此特定的Office更新(KB978382)(对于Office Ultimate):

HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{91120000-002E-0000-0000-0000000FF1CE}_ULTIMATER_{6DE3DABF-0203-426B-B330-7287D1003E86}

which kindly shows the uninstall command of: 其中显示卸载命令:

msiexec /package {91120000-002E-0000-0000-0000000FF1CE} /uninstall {6DE3DABF-0203-426B-B330-7287D1003E86}

and the last GUID seems constant between different versions of Office. 并且最后一个GUID在不同版本的Office之间似乎是不变的。

I've also found the update like this: 我也发现了这样的更新:
$wu = new-object -com "Microsoft.Update.Searcher"
$wu.QueryHistory(0,$wu.GetTotalHistoryCount()) | where {$_.Title -match "KB978382"}

I like this search because it doesn't require any poking around in the registry, but: 我喜欢这个搜索,因为它不需要在注册表中进行任何调查,但是:

Question 2: If I've found it like this, what can I do with the found information to facilitate the Uninstall? 问题2:如果我发现它是这样的,我怎么处理找到的信息以方便卸载?

Thanks 谢谢

Expanding on your second approach (using Microsoft.Update.Searcher), this solution should allow you to search for an update by Title then uninstall it: 扩展您的第二种方法(使用Microsoft.Update.Searcher),此解决方案应允许您按标题搜索更新,然后将其卸载:

$TitlePattern = 'KB978382'

$Session = New-Object -ComObject Microsoft.Update.Session

$Collection = New-Object -ComObject Microsoft.Update.UpdateColl
$Installer = $Session.CreateUpdateInstaller()
$Searcher = $Session.CreateUpdateSearcher()

$Searcher.QueryHistory(0, $Searcher.GetTotalHistoryCount()) | 
    Where-Object { $_.Title -match $TitlePattern } |
    ForEach-Object {
        Write-Verbose "Found update history entry $($_.Title)"
        $SearchResult = $Searcher.Search("UpdateID='$($_.UpdateIdentity.UpdateID)' and RevisionNumber=$($_.UpdateIdentity.RevisionNumber)")
        Write-Verbose "Found $($SearchResult.Updates.Count) update entries"
        if ($SearchResult.Updates.Count -gt 0) {
            $Installer.Updates = $SearchResult.Updates
            $Installer.Uninstall()
            $Installer | Select-Object -Property ResultCode, RebootRequired, Exception
            # result codes: http://technet.microsoft.com/en-us/library/cc720442(WS.10).aspx
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM