简体   繁体   English

使用 PowerShell 远程执行软件中心包

[英]Remotely execute Software Center Package using PowerShell

I have a specific use case where I need to remotely execute the Windows 10 version 1809 OS upgrade package which is published in Software Center under the Operating Systems tab on a Windows 10 v1709 PC.我有一个特定的用例,我需要远程执行 Windows 10 版本 1809 操作系统升级包,该升级包在 Windows 10 v1709 PC 上的操作系统选项卡下的软件中心中发布。 I have a PowerShell one-liner that will do it remotely when the PC is logged in with an admin account (the same account that the PC is logged in with) as shown below:我有一个 PowerShell one-liner,当 PC 使用管理员帐户(与 PC 登录的帐户相同)登录时,它将远程执行此操作,如下所示:

Invoke-Command -ComputerName Computer001 {(New-Object -ComObject "UIResource.UIResourceMgr").ExecuteProgram("*", "OS_UpGrade", $true)} 

That works perfectly when the target PC is logged in with the same account that I have used to run PowerShell terminal with.当目标 PC 使用我用来运行 PowerShell 终端的相同帐户登录时,这非常有效。 But when the PC (Computer001) is logged off, and I run the same command, I get this error:但是当 PC (Computer001) 被注销时,我运行相同的命令,我得到这个错误:

"Error HRESULT E_FAIL has been returned from a call to a COM component.
+ CategoryInfo          : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
+ PSComputerName        : Computer001"

I am guessing that the ComObject cannot be called when the PC is logged off, is that correct and is there any way around that?我猜测在 PC 注销时无法调用 ComObject,这是正确的,有什么办法可以解决这个问题吗?

Any guidance would be greatly appreciated.任何指导将不胜感激。

I took a deeper look at the documentation here.我更深入地查看了此处的文档。

The issue is specifically the COM object you are calling (as you expected).问题特别在于您正在调用的 COM 对象(如您所料)。

The SDK for SCCM specifically mentions this COM object is the UI for CM. SCCM 的 SDK 特别提到这个 COM 对象是 CM 的 UI。 UIResource.UIResourceMgr. UIResource.UIResourceMgr。 It also notes in the SDK that this particular object can be difficult to call because it relies on user context.它还在 SDK 中指出,此特定对象可能难以调用,因为它依赖于用户上下文。

I'm afraid you are going to have to find an execution that does not rely on calling the UI Resource.恐怕您将不得不找到不依赖于调用 UI 资源的执行。

It may be easier to run this via PSExec than a PowerShell script invoking SCCM as I presume you cannot use SCCM itself to invoke the installation remotely.通过 PSExec 运行它可能比调用 SCCM 的 PowerShell 脚本更容易,因为我认为您不能使用 SCCM 本身来远程调用安装。

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

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