Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke-Command error message on localhost loopback #3874

Closed
Liturgist opened this issue May 27, 2017 · 6 comments
Closed

Invoke-Command error message on localhost loopback #3874

Liturgist opened this issue May 27, 2017 · 6 comments
Labels
Issue-Discussion the issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif Resolution-Answered The question is answered. WG-Cmdlets-Core cmdlets in the Microsoft.PowerShell.Core module

Comments

@Liturgist
Copy link

Liturgist commented May 27, 2017

Steps to reproduce

Invoke-Command -ComputerName localhost -ScriptBlock { dir }

Expected behavior

Directory contents are presented.

Actual behavior

PS C:\Program Files\PowerShell\6.0.0-beta.1> Invoke-Command -ComputerName localhost -ScriptBlock { dir }
[localhost] Connecting to remote server localhost failed with the following error message : Access is denied. For more
information, see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (localhost:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : AccessDenied,PSSessionStateBroken

If using the loopback adapter to localhost is prohibited unless elevated, the error message should include that information. It clearly knows the problem. Not sure of the implications on Linux.

Environment data

> $PSVersionTable
PSVersion                      6.0.0-beta
PSEdition                      Core
BuildVersion                   3.0.0.0
CLRVersion
GitCommitId                    v6.0.0-beta.1
OS                             Microsoft Windows 10.0.15063
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
@iSazonov iSazonov added WG-Cmdlets-Core cmdlets in the Microsoft.PowerShell.Core module Issue-Discussion the issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif labels May 27, 2017
@Liturgist
Copy link
Author

This appears to be a security restriction by design on Windows.

@a-kanaan
Copy link

a-kanaan commented Mar 7, 2018

I am getting same error
but if remove ComputerName then, it will work, but I think it's not a loopback work

@iSazonov
Copy link
Collaborator

ComputerName is implemented as remoting that requires elevated rights.

@iSazonov iSazonov added the Resolution-Answered The question is answered. label Mar 24, 2018
@Liturgist
Copy link
Author

Does not work using "Run as Administrator." What elevated rights are required?

@iSazonov
Copy link
Collaborator

Did you set remoting up?

@FcoJavier0099
Copy link

FcoJavier0099 commented Jul 12, 2019

Well, you need to enlist the localhost (with its hostname) to use remoting.
These were the steps that I follow:
(1) Start a new powershell window with administrator privilegies (Run as Administrator)
(2) Retrive your localhost name with the command: hostname, in my example its name is "PROCDB01"
(3) Enlist this hostname in the list of trusted servers with a comman like this:

# procdb01 is the localhost
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "procdb01,procdb02,procdb03,procdb04,procdb05"

(4) Activate Remoting with these commands:

Winrm qc
Enable-PSRemoting

(5) Test it

Invoke-Command -ComputerName procdb01 -ScriptBlock {hostname}
Invoke-Command -ComputerName localhost -ScriptBlock {hostname}

Note: I'am using this version:

PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14393.2828
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.2828
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Discussion the issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif Resolution-Answered The question is answered. WG-Cmdlets-Core cmdlets in the Microsoft.PowerShell.Core module
Projects
None yet
Development

No branches or pull requests

4 participants