我有一个与Windows 2003,2008和2008r2服务器的networking。 我有一个PowerShell脚本,我写了使用“Microsoft.Update”COM对象修补本地机器。 (类似于Windows Update PowerShell Remoting 。)我的脚本在本地非常有效,但是我想远程使用它的function,因为我有相当数量的服务器来pipe理。 在这种情况下,这种情况就会下降(类似于另一个没有解决的情况)。
然而,我却能够把失败的范围缩小到特定class级的两种方法。
(New-Object -ComObject "Microsoft.Update.Session").CreateUpdateDownloader() (New-Object -ComObject "Microsoft.Update.Session").CreateUpdateInstaller()
如果您以pipe理员身份在本地运行这些PowerShell,则不会有任何问题。 如果您尝试使用invoke-command(或enter-session或winrs),则会出现以下错误。 (这是使用本地主机进行testing,但任何主机都可以,我也尝试了不同的authentication方法,例如:credssp和Kerberos。
PS C:\> Invoke-Command -ComputerName localhost -ScriptBlock { (New-Object -ComObject "microsoft.update.session").createUpdateDownloader()} Exception calling "CreateUpdateDownloader" with "0" argument(s): "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))" + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ComMethodTargetInvocation
我曾经在博客中看到过这个bug,但没有对这个声明做任何备份。 两个解决方法存在,都不使我感到高兴。
我打开其他方式来远程运行主机上的更新,因为这似乎是一个很多人打的问题。
我发现了一些解释消息的文档 ,但没有解释原因或解决方法。
返回值如果成功则返回S_OK。 否则,返回一个COM或Windows错误代码。
This method can also return the following error codes. Return code Description E_INVALIDARGA parameter value is invalid. E_ACCESSDENIED This method cannot be called from a remote computer.
它如何知道我在远程计算机上?
你不能这样做,因为MS不允许你通过WUApi去做。
详细信息可以在这里find: http : //msdn.microsoft.com/en-us/library/windows/desktop/aa387288(v=vs.85).aspx
您可以尝试使用计划任务来完成此任务。
这样的命令需要在远程机器上以特权运行,因此需要以域pipe理员用户或远程机器上的pipe理员身份运行。
如果你是第一个案件,我没有任何帮助,但你只是本地pipe理员,而不是远程,使用这样的get-credential
。
$cred = get-credential Invoke-Command -ComputerName localhost -credential $cred -scriptblock {}
让一个更直接的forms是Invoke-Command
请求凭证:
Invoke-Command -scriptblock {$ENV:username} -Credential ""