首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行远程PowerShell办公室卸载脚本

运行远程PowerShell办公室卸载脚本
EN

Stack Overflow用户
提问于 2015-02-19 03:26:25
回答 1查看 869关注 0票数 0

KB2956128让我网络中的用户感到头疼。我不在这个环境中运行WSUS,所以我打算使用PS脚本来处理卸载。无论如何,下面的脚本应该可以工作

代码语言:javascript
复制
$comp = 'PC03'
$scrblock = 
{
$TitlePattern = 'KB2956128'

$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
        }
    }
}
Invoke-Command -ComputerName $comp -ScriptBlock $scrblock -Credential 'myDomain\administrator'

相反,我得到了这个错误

代码语言:javascript
复制
Exception calling "CreateUpdateInstaller" with "0" argument(s): "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation
    + PSComputerName        : PC03

Exception calling "QueryHistory" with "2" argument(s): "Exception from HRESULT: 0x80240007"
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation
    + PSComputerName        : PC03

我不太明白为什么访问被拒绝了。有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2015-02-19 07:13:15

简短的回答是远程调用的ComObject does not allow the CreateUpdateInstaller。您只能在本地执行此操作,而不能通过会话或任何其他远程处理。但是,您可以使用psexec以system身份远程执行脚本。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28592175

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档