Azure – Can’t connect to WinRM on Domain controller

active-directoryazuredomain-controllerwindows-server-2016winrm

I have set up a domain controller server on Azure with Windows Server 2016. Now I want to connect to this server using PSSession.

WinRM is enabled, all firewall rules are ok, inbound rules on Azure network security group too, but I can't connect to the server.

Enter-PSSession : Connecting to remote server a.b.c.d failed with the
following error message : WinRM cannot complete the operation. Verify
that the specified computer name is valid, that the computer is
accessible over the network, and that a firewall exception for the
WinRM service is enabled and allows access from this computer. By
default, the WinRM firewall exception for public profiles limits
access to remote computers within the same local subnet.

I can connect to this server using RDP only, but no success with WinRM.

Any thoughts?

Best Answer

I can connect to this server using RDP only, but no success with WinRM.

To Winrm Azure VM, we should add port 5985 to Azure VM NSG inbound rules. Also we should add port 5985 to Windows server 2016 windows firewall inbound rules.

We can follow this step to enable winrm for this VM:

1.Add port 5985 to Azure VM NSG inbound rules.
2.Add port 5985 to Azure VM windows firewall inbound rules.
3.Enable Winrm settings in Azure VM, use this command winrm quickconfig
4.Add trust host to your local PC, use this command

Set-Item wsman:\localhost\Client\TrustedHosts -value *

5.Then use this script to Winrm your VM:

$username = 'jason'
$pass = ConvertTo-SecureString -string 'Password' -AsPlainText -Force
$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $pass
$s = New-PSSession -ConnectionUri 'http://13.xx.xx.89:5985' -Credential $cred -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)
Invoke-Command -Session $s -ScriptBlock {get-process}

More information please refer to this link.