PowerShell WinRM Setup: Enable Remote Management

PowerShell WinRM Setup: Enable Remote Management

PowerShell Tips Editor 4 min read
PowerShell WinRM Setup: Enable Remote Management

PowerShell remoting is one of the most powerful features in Windows administration, but it only works when WinRM is properly configured on both the client and the target machine. Attempting to Invoke-Command against an unconfigured host returns a vague connection error that sends admins chasing the wrong problems. This guide walks you through every step to powershell winrm enable, configure trusted hosts, open firewall ports, and verify the connection is working.

Quick Answer / TL;DR

Run Enable-PSRemoting -Force on the target machine as Administrator. On the client, add the target to TrustedHosts if not domain-joined: Set-Item WSMan:\localhost\Client\TrustedHosts -Value 'server01'.

Enable-PSRemoting Command

Enable-PSRemoting configures the WinRM service, registers the PowerShell session configuration, and sets the necessary firewall rules on the local machine. Run it on every machine that will receive remote connections. The -Force flag suppresses prompts, making it suitable for deployment scripts. Run PowerShell as Administrator — this command requires elevation.

# Run on the TARGET machine as Administrator
Enable-PSRemoting -Force

# Verify WinRM service is running
Get-Service WinRM | Select-Object Name, Status, StartType
Name  Status StartType
----  ------ ---------
WinRM Running Automatic

Configure TrustedHosts for Workgroup

In a domain environment, Kerberos handles authentication automatically. In a workgroup (or when connecting by IP address), you must add the target to the client’s TrustedHosts list. This tells WinRM to accept NTLM authentication for those hosts. Use a wildcard (*) only in lab environments — in production, list specific hostnames.

# Add a single host (run on the CLIENT machine)
Set-Item WSMan:\localhost\Client\TrustedHosts -Value 'server01.contoso.com' -Force

# Add multiple hosts
Set-Item WSMan:\localhost\Client\TrustedHosts -Value 'server01,server02,10.0.0.50' -Force

# View current TrustedHosts
Get-Item WSMan:\localhost\Client\TrustedHosts

Open Firewall Port 5985/5986

Enable-PSRemoting creates a firewall rule for HTTP (port 5985) on domain and private networks. If you need to remote over a public network profile, or if you are setting up HTTPS (port 5986), create the firewall rules explicitly. Always prefer the named rule approach over opening raw ports.

# Open HTTP WinRM port (already done by Enable-PSRemoting on domain/private)
New-NetFirewallRule -DisplayName 'WinRM HTTP' -Direction Inbound `
    -Protocol TCP -LocalPort 5985 -Action Allow -Profile Domain,Private

# Open HTTPS WinRM port
New-NetFirewallRule -DisplayName 'WinRM HTTPS' -Direction Inbound `
    -Protocol TCP -LocalPort 5986 -Action Allow -Profile Domain,Private

# Verify rules
Get-NetFirewallRule -DisplayName 'WinRM*' | Select-Object DisplayName, Enabled, Profile

Set Up HTTPS with Certificate

HTTP WinRM transmits credentials protected only by NTLM encryption. For production environments, use HTTPS (port 5986) with a certificate. Create or import a certificate whose Subject matches the machine’s hostname, then create the HTTPS listener.

# Get the certificate thumbprint for the machine's hostname
$cert = Get-ChildItem Cert:\LocalMachine\My |
    Where-Object { $_.Subject -like "*CN=server01*" } |
    Select-Object -First 1

# Create HTTPS WinRM listener
New-WSManInstance -ResourceURI winrm/config/Listener `
    -SelectorSet @{Address='*'; Transport='HTTPS'} `
    -ValueSet @{Hostname='server01.contoso.com'; CertificateThumbprint=$cert.Thumbprint}

Write-Host "HTTPS listener created with cert: $($cert.Thumbprint)"

Test WinRM Connection

Test-WSMan is the correct tool for confirming WinRM connectivity before attempting to run remote commands. It attempts to contact the WinRM service on the target and returns version information on success. A clean response means WinRM is running and the port is reachable.

# Test basic WinRM connectivity
Test-WSMan -ComputerName server01

# Test with credentials (workgroup)
$cred = Get-Credential
Test-WSMan -ComputerName server01 -Credential $cred -Authentication Negotiate

# Quick connectivity test via Invoke-Command
Invoke-Command -ComputerName server01 -ScriptBlock { $env:COMPUTERNAME } -Credential $cred

Troubleshoot Common WinRM Errors

The most frequent WinRM errors and their resolutions:

  • “WinRM cannot complete the operation” — WinRM service is not running on the target. Run Enable-PSRemoting -Force on the target.
  • “Access is denied” — Credentials are wrong or TrustedHosts is not configured on the client for non-domain connections.
  • “The client cannot connect to the destination” — Firewall is blocking port 5985/5986. Check Get-NetFirewallRule -DisplayName 'WinRM*'.
# Diagnose WinRM configuration on local machine
winrm get winrm/config/client
winrm get winrm/config/service

# Check WinRM listener is bound to the right address
Get-WSManInstance -ResourceURI winrm/config/listener -SelectorSet @{Address='*'; Transport='HTTP'}

Common Errors and Fixes

  • TrustedHosts required for non-domain workgroup remoting. Without adding the target to TrustedHosts, NTLM authentication is rejected by WinRM even with correct credentials. Always set TrustedHosts on the client when connecting outside a Kerberos domain.
  • Kerberos vs NTLM auth behavior differs on workgroup machines. Domain-joined machines default to Kerberos; workgroup machines use NTLM. Force the authentication mechanism with -Authentication Negotiate to let the client and server negotiate automatically.

Related Cmdlets / See Also

Wrapping Up

WinRM setup is a one-time task per machine: run Enable-PSRemoting on targets, configure TrustedHosts on clients for workgroup scenarios, and use HTTPS in production for encrypted credential transport. Once configured, PowerShell remoting is the most powerful tool in your administration toolkit.

Send-Item -To