I’m trying to implement PowerShell remoting (for PowerShell script execution on a remote server). My remote server is running Windows Server 2008 and PowerShell v2.
From an elevated permission PS console, I have executed the following cmdlet:
Enable-PSRemoting
Returned to console:
WinRM already is set up to receive requests on this machine.
WinRM already is set up for remote management on this machine.
From an elevated PowerShell session on the client machine, I executed the following cmdlet:
Enter-PSSession –ComputerName [remote_server_name]
This time, returned to console:
Enter-PSSession : Connecting to remote server [remote_server_name] failed with the following error message : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: “winrm quickconfig”. For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:1
+ Enter_PSSession –ComputerName [remote_server_name]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : Invalid/argument: ([remote_server_name]:string) [Enter-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed
I executed the “winrm quickconfig” as per the error message suggestion. Once again, returned to console:
WinRM already is set up to receive requests on this machine.
WinRM already is set up for remote management on this machine.
Retrying
Enter-PSSession –ComputerName [remote_server_name]
from the client machine retrurns the same error.
I double checked that the WinRM service is running on the remote server. The Windows Remote Management (HTTP-In) firewall rule is configured for TCP protocol, local port 5985 and all remote ports.
Even when I execute
Get-Service WinRM –ComputerName [remote_server_name]
from the client machine, we see returned to console, confirming that the WinRM service is indeed running on the remote server:
Status Name DisplayName
------ ---- -----------
Running WinRM Windows Remote Management (WS-Manag…
Execution of the following command on the remote machine
WinRM Enumerate WinRM/Config/Listener
returns to console, demonstrating the correct port is open:
Listener [Source=”GPO”]
Address = *
Port = 5985
Hostname Enabled = true
URLPrefix = wsman
CertificateThumbprint ListeningOn = null
But, execution of
$remoteServer = [test_server_name]
$port = 5985
$connection = New-Object System.Net.Sockets.TcpClient($remoteServer, $port)
if ($connection.Connected) {
Write-Host "Success"
}
else {
Write-Host "Failed"
}
returns the following error message:
New-Object : Exception calling ".ctor" with "2" argument(s): "No connection could be made because the target machine actively refused it [remote_server_ipaddress]:5985"
At line:4 char:15
+ ... onnection = New-Object System.Net.Sockets.TcpClient($ipaddress, $port ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
I have another remote server, running Windows Server 2012 R2 with PowerShell v4. I have enabled PS remoting on this box without issue and can remotely execute PS scripts from the same client.
So, what am I missing? Is there a possibility that there is a compatibility problem between PowerShell versions?
My client PC is running PowerShell 5, my correctly functioning remote server is running PowerShell 4, my failing remote server is running PowerShell 2.
Insights, guidance, advice very welcome. Thanks for looking.
UPDATE:
I've since updated the .Net Framework on bothe test VMs to .Net 4.7.2 and installed PowerShell 4 on the affected VM (same as the correctly functioning box).
Whilst comparing WinRM related registry entries between my working VM and the affected machine, I found the key:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WSMAN\Service
On the working VM, I found a 32-bit 'allow-remote-requests', assigned a value of 1. This entry was missing from the affected machine's registry. I added it, rebooted the machine, retried the connection request.
Still, same problem persists.
netsh winhttp show proxy
– Maximilian Burszley