Powershell Remote:Microsoft.Update.Session,拒绝访问:0x80070005

kly*_*lyd 5 com powershell

我编写了一个脚本,使用Microsoft.Update.Session COM对象在计算机上搜索/下载/安装Windows更新.在本地运行时它可以正常工作,但是当通过远程会话或通过Invoke-Command运行时,我在Microsoft.Update.Session.CreateUpdateDownloader()上收到拒绝访问(0x80070005)错误

如果我尝试直接创建Downloader对象,代码重现问题,我会收到同样的错误:

$oUpdateDownloader = new-object -com "Microsoft.Update.Downloader" 
Run Code Online (Sandbox Code Playgroud)

我是远程计算机的管理员,并且将凭证(对于我自己明确地或任何其他管理员帐户)传递给计算机似乎没有任何改变.

我已经多次看到这个错误,但似乎没有任何关于解决问题的信息......

有任何想法吗?

arg*_*nym 8

当您处于远程 PowerShell 会话中时,您在此远程计算机上的登录会话将被标记为“网络”登录(登录类型:3)。由于某些模糊的(安全性?出售 SCCM?)原因,部分Windows 更新代理 COM API 被限制为只能由本地登录的管理员使用。

建议使用 PsExec 和计划任务作为解决方法。

IMO,最无缝(并且仍然安全的解决方案是促进PowerShell会话配置/ JEA的RunAs 风格的“本地虚拟帐户”功能。通常,JEA 用于“限制”用户在远程计算机 PowerShell 上可以执行的操作,但我们在这里(ab-)使用它来获得完全访问权限,就好像我们是本地登录的管理员一样。

ComputerB(1.) 在(远程服务器)上创建新的无限制(且持久!)会话配置:

New-PSSessionConfigurationFile -RunAsVirtualAccount -Path .\VirtualAccount.pssc
# Note this will restart the WinRM service:
Register-PSSessionConfiguration -Name 'VirtualAccount' [-ShowSecurityDescriptorUI] -Path .\VirtualAccount.pssc -Force
# Check the Permission property:
Get-PSSessionConfiguration -Name 'VirtualAccount'
# Those users will have full unrestricted access to the system!
Run Code Online (Sandbox Code Playgroud)

(2.) 从ComputerA(本地客户端)连接到 ComputerB 上的无限制会话配置:

New-PSSession -ComputerName 'ComputerB' -ConfigurationName 'VirtualAccount' | Enter-PSSession
[ComputerB]: new-object -com "Microsoft.Update.Downloader" # Yay!
Run Code Online (Sandbox Code Playgroud)


And*_*der 5

这是一个已知的问题。实际的 COM 对象本身似乎存在错误,因为使用 VBScript、PowerShell 甚至 C# 时都会出现此问题。有一篇讨论使用 PowerShell 管理 Windows 更新的好文章,可以在此处找到。

解决方法是在计算机上设置计划任务,您可以按照您认为合适的方式调用该任务。