允许Enter-PSSession从本地系统帐户工作

我有一个PowerShell脚本,通过Enter-PSSession在远程服务器上创build一个Windows PowerShell会话(PSSession),这两个服务器都没有连接到一个DOMAIN。 此脚本是从本地系统帐户下作为服务运行的程序调用的。 出于某种原因,将PowerShell脚本作为本地系统帐户运行会导致Enter-PSSession返回错误。

例如,从本地pipe理员帐户运行时,以下命令会询问我的密码并成功连接:

 Enter-PSSession -ComputerName #### -Credential #### 

但是,如果通过psexec使用本地系统或networking服务帐户运行PowerShell,请执行以下操作:

 PsExec -i -s powershell.exe PsExec -i -u "NT AUTHORITY\NetworkService" powershell.exe 

然后再次尝试命令它要求我的密码,只是返回一个错误消息:

 Enter-PSSession : Connecting to remote server #### failed with the following error message : WinRM cannot process the request. The following error with errorcode 0x8009030d occurred while using Negotiate authentication: A specified logon session does not exist. It may already have been terminated. 

任何想法如何让Enter-PSSession命令在本地系统帐户下工作?

您不能在脚本中使用Enter-PSSession ,它仅用于交互式login。 改用Invoke-Command