Powershell remote enabling

powershellpowershell-remoting

I am not able to connect to remote machine using powershell. The procedures i did is:

  1. Enable-PSRemoting -Force
  2. Set-Item WSMan:\localhost\Client\TrustedHosts *
  3. restart-Service winrm
  4. Enter-PSSession IpAddress

When i run the last step (4th one) from my server machine i am getting an error like:

Enter-PSSession : Connecting to
remote server failed with the
following error message : Access is
denied.

I have tried all the above 4 steps in both client and server machine. Please help

Thanks
Prav

Best Solution

Check the port on the remote machine

PS Z:> cd WSMan:\localhost\Listener
PS WSMan:\localhost\Listener> dir
[cut]
PS WSMan:\localhost\Listener> cd .\Listener_1084132640
PS WSMan:\localhost\Listener\Listener_1084132640> dir
WSManConfig:
Microsoft.WSMan.Management\WSMan::localhost\Listener\Listener_1084132640
Name Value
---- -----
Address *
Transport HTTP
Port 5985

Then connect with the correct port

$remotePowerShellPort = 5985 $ConnectionURI = ("http://{0}:{1}" -f $targetServer, $remotePowerShellPort)
$remoteSession = New-PSSession -ConnectionURI $ConnectionURI
Invoke-Command -Session $remoteSession -ScriptBlock { dir }
Remove-PSSession $remoteSession