PowerShell:如何查找和卸载 MS Office 更新 [英] PowerShell: How to find and uninstall a MS Office Update
问题描述
我一直在寻找一种干净的方法来卸载大量工作站上的 MSOffice 安全更新.我发现了一些尴尬的解决方案,但没有什么比使用 PowerShell 和 get-wmiobject
和 Win32_QuickFixEngineering
和 .Uninstall
方法更干净或更通用结果的对象.
[显然,Win32_QuickFixEngineering 仅指 Windows 补丁.请参阅:http://social.technet.microsoft.com/Forums/en/winserverpowershell/thread/93cc0731-5a99-4698-b1d4-8476b3140aa3 ]
问题 1:有没有办法使用 get-wmiobject
来查找 MSOffice 更新?有这么多的类和命名空间,我不得不怀疑.
可以在此处的注册表中找到此特定的 Office 更新 (KB978382)(对于 Office Ultimate):
HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{91120000-002E-0000-0000-0000000FF1CE}_ULTIMATER_{6DE3DABF-0203-426B-B330-7287D1003E8}
p8
其中显示卸载命令:
msiexec/package {91120000-002E-0000-0000-0000000FF1CE}/uninstall {6DE3DABF-0203-426B-B330-7287D1003E86}
并且最后一个 GUID 在不同版本的 Office 之间似乎是不变的.
我也发现了这样的更新:$wu = new-object -com "Microsoft.Update.Searcher"
$wu.QueryHistory(0,$wu.GetTotalHistoryCount()) |其中 {$_.Title -match "KB978382"}
我喜欢这个搜索,因为它不需要在注册表中进行任何检查,但是:
问题 2:如果我找到了这样的信息,我可以如何处理找到的信息以方便卸载?
谢谢
扩展您的第二种方法(使用 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 {写详细找到更新历史条目 $($_.Title)"$SearchResult = $Searcher.Search("UpdateID='$($_.UpdateIdentity.UpdateID)' and RevisionNumber=$($_.UpdateIdentity.RevisionNumber)")写详细找到 $($SearchResult.Updates.Count) 更新条目"如果($SearchResult.Updates.Count -gt 0){$Installer.Updates = $SearchResult.Updates$Installer.Uninstall()$安装程序|Select-Object -Property ResultCode、RebootRequired、异常# 结果代码:http://technet.microsoft.com/en-us/library/cc720442(WS.10).aspx}}
I've been hunting for a clean way to uninstall an MSOffice security update on a large number of workstations. 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.
[Apparently, Win32_QuickFixEngineering only refers to Windows patches. See: 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? 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):
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.
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?
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:
$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
}
}
这篇关于PowerShell:如何查找和卸载 MS Office 更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!