2

I have a PowerShell script that creates a Windows PowerShell session (PSSession) on a remote server via Enter-PSSession, both servers are not connected to a DOMAIN. This script is called from a program that is running as a service under the local systems account. For some reason, running the PowerShell script as a local systems account causes the Enter-PSSession to return an error.

For example, when run from a local admin account the following command asks for my password and connects successfully:

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

However, if I run PowerShell using a Local Systems or Network Service account via psexec:

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

Then try the command again it asks for my password and simply returns an error message:

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.

Any idea how I can get the Enter-PSSession command to work under a local systems account?

2
  • The local system account is local only (thus the "local" part). It cannot be used to access any remote resources. You can try the network service account and see if that will work for you.
    – Rex
    Commented Feb 6, 2015 at 20:50
  • Trying to run the command under the network service results in the same error message. Have updated my question to include this example. Commented Feb 11, 2015 at 10:25

1 Answer 1

1

You cannot use Enter-PSSession in a script, it was intended for interactive logons only. Use Invoke-Command instead.

1
  • 1
    In my working example I am not using Enter-PSSession in a script but as an interactive logon. Commented Feb 23, 2015 at 15:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .