Manage a Windows server with PowerShell Remoting over HTTPS
Set up PowerShell Remoting over HTTPS on Windows Server: certificate, WinRM listener on port 5986, firewall limited to your IP address and secure connection.
On this page
Your values
Enter them once and the commands in this guide update.
PowerShell Remoting lets you run commands on your server from your workstation, without opening a graphical session. This guide sets up encrypted access over HTTPS on port 5986, with a certificate verified by the client and a firewall that only accepts your IP address.
How it works
PowerShell Remoting relies on the WinRM service, which is enabled by default on Windows Server.
| Port | Transport | Use in this guide |
|---|---|---|
5985 |
HTTP | Remains available locally, but closed from the network |
5986 |
HTTPS | Only remote access, limited to your IP address |
From a workstation that is not in a domain, authentication uses NTLM, which does not prove the identity of the server. The HTTPS certificate fills this gap: your workstation checks that it is talking to your server before sending anything.
Prerequisites
- A server running Windows Server 2019, 2022 or 2025, reachable over RDP with an administrator account.
- An administration workstation running Windows, with administrator rights. The WinRM transport is not supported by PowerShell on Linux and macOS.
- The public IP address of this workstation, preferably a fixed one.
- A host name for the server, for example
srv.your-domain.com.
Choose the host name
The name used when connecting must be identical to the one in the certificate. There are two options:
- With a domain: create an
ADNS record pointingsrv.your-domain.comto your server's address. - Without a DNS record: choose a name and declare it in the
hostsfile of your workstation, as shown in step 6.
1. Check WinRM on the server
Open PowerShell as administrator on the server:
Get-Service WinRM | Format-Table Name, Status, StartType
Test-WSManThe service must be in the Running state and Test-WSMan must return information about the protocol. If not, re-enable the service:
Enable-PSRemoting -Force2. Create the certificate
Option A: self-signed certificate
This option suits a single administrator well, because you install the certificate on your workstation yourself. Here it is valid for two years, and its private key is not exportable.
$hostName = 'srv.your-domain.com'
$cert = New-SelfSignedCertificate -DnsName $hostName -CertStoreLocation 'Cert:\LocalMachine\My' -KeyExportPolicy NonExportable -NotAfter (Get-Date).AddYears(2)
$cert | Format-List Subject, Thumbprint, NotAfter
New-Item -ItemType Directory -Path 'C:\WinRM' -Force | Out-Null
Export-Certificate -Cert $cert -FilePath 'C:\WinRM\winrm-https.cer'The .cer file only contains the public part of the certificate. Note the thumbprint (Thumbprint): you will compare it on your workstation.
Option B: certificate from a recognized authority
If you already have a certificate for this name in PFX format, import it. Its CN field must match the host name and it must allow server authentication.
$pfxPassword = Read-Host 'PFX password' -AsSecureString
Import-PfxCertificate -FilePath 'C:\WinRM\certificate.pfx' -CertStoreLocation 'Cert:\LocalMachine\My' -Password $pfxPasswordThen delete the PFX file from the server. With this option, you do not need to import the certificate on your workstation.
3. Create the HTTPS listener
$hostName = 'srv.your-domain.com'
$cert = Get-ChildItem Cert:\LocalMachine\My |
Where-Object { $_.Subject -like "CN=$hostName*" } |
Sort-Object NotAfter | Select-Object -Last 1
New-WSManInstance -ResourceURI winrm/config/Listener `
-SelectorSet @{ Address = '*'; Transport = 'HTTPS' } `
-ValueSet @{ Hostname = $hostName; CertificateThumbprint = $cert.Thumbprint }Check the result:
Get-WSManInstance -ResourceURI winrm/config/Listener -Enumerate |
Format-Table Transport, Port, Hostname, Enabled, CertificateThumbprint
Get-NetTCPConnection -LocalPort 5986 -State ListenDo not use winrm quickconfig -transport:https with a self-signed certificate: this command refuses it.
4. Open port 5986 for your IP address only
From your RDP session, this command displays the public address as seen by the server (adjust 3389 if you use a different RDP port):
(Get-NetTCPConnection -LocalPort 3389 -State Established).RemoteAddressIf this address is indeed that of your administration workstation, create the rule:
New-NetFirewallRule -Name 'WinRM-HTTPS-Admin' -DisplayName 'WinRM HTTPS - admin workstation' `
-Direction Inbound -Action Allow -Protocol TCP -LocalPort 5986 -RemoteAddress YOUR_IP -Profile AnyWith the graphical interface
- Create an inbound rule for TCP port
5986, as explained in the Windows firewall guide, with the Allow the connection action and all profiles. - Open the rule's Properties, then the Scope tab.
- Under Remote IP address, choose These IP addresses, then add your address.
If your plan offers a firewall that can be configured from the console, also allow this port there for your address.
5. Close remote access over HTTP
By default, Windows allows port 5985 on the local network, and a public address may share its subnet with other servers. Disable these rules. The HTTP listener stays in place for local tools.
Get-NetFirewallRule -Name 'WINRM-HTTP-In-TCP*' | Disable-NetFirewallRule
Get-NetFirewallRule -Name 'WINRM-HTTP-In-TCP*' | Format-Table Name, Enabled, ProfileIf you run Enable-PSRemoting again later, these rules will be re-enabled: repeat this step then.
6. Prepare the administration workstation
Open PowerShell as administrator on your workstation.
If the name does not exist in the public DNS, declare it:
Add-Content -Path "$env:SystemRoot\System32\drivers\etc\hosts" -Value 'YOUR_SERVER_IP srv.your-domain.com'With a self-signed certificate, copy C:\WinRM\winrm-https.cer to your workstation, for example by copy-paste in the RDP session, then import it from the folder where it is located:
Import-Certificate -FilePath '.\winrm-https.cer' -CertStoreLocation 'Cert:\LocalMachine\Root'7. Connect
The account name is written SERVER_NAME\YOUR_USER. The hostname command gives the server name. On a domain controller, use DOMAIN\YOUR_USER.
$cred = Get-Credential -UserName 'SERVER_NAME\YOUR_USER' -Message 'Server administrator account'
Enter-PSSession -ComputerName srv.your-domain.com -UseSSL -Credential $credThe prompt then shows the server name. Test, then exit:
hostname
whoami
Exit-PSSessionTo run a command without an interactive session, or to reuse a connection and copy a file:
Invoke-Command -ComputerName srv.your-domain.com -UseSSL -Credential $cred -ScriptBlock { Get-Service WinRM }
$session = New-PSSession -ComputerName srv.your-domain.com -UseSSL -Credential $cred
Copy-Item -Path '.\script.ps1' -Destination 'C:\WinRM\' -ToSession $session
Remove-PSSession $sessionVerify the configuration
On the server, check the firewall rule and that no unencrypted transport is allowed. The last two parameters must be false:
Get-NetFirewallRule -Name 'WinRM-HTTPS-Admin' | Get-NetFirewallAddressFilter | Format-Table RemoteAddress
Get-NetFirewallPortFilter -Protocol TCP |
Where-Object { $_.LocalPort -contains '5986' } |
Get-NetFirewallRule | Format-Table Name, Enabled, Action, Profile
Get-Item WSMan:\localhost\Service\AllowUnencrypted
Get-Item WSMan:\localhost\Service\Auth\BasicOnly one active rule must allow port 5986. On your workstation, the HTTPS port must respond and the HTTP port must not:
Test-NetConnection srv.your-domain.com -Port 5986 -WarningAction SilentlyContinue | Select-Object TcpTestSucceeded
Test-NetConnection srv.your-domain.com -Port 5985 -WarningAction SilentlyContinue | Select-Object TcpTestSucceeded
Test-WSMan -ComputerName srv.your-domain.com -UseSSLThe first test must display True, the second False. Finally, from another Internet connection, for example a mobile hotspot, port 5986 must also display False.
Update the configuration
Your IP address has changed
Connect to the server over RDP and replace the allowed address:
Set-NetFirewallRule -Name 'WinRM-HTTPS-Admin' -RemoteAddress YOUR_IPRenew the certificate
Before it expires, create a new certificate as in step 2, then bind it to the listener:
$hostName = 'srv.your-domain.com'
$cert = Get-ChildItem Cert:\LocalMachine\My |
Where-Object { $_.Subject -like "CN=$hostName*" } |
Sort-Object NotAfter | Select-Object -Last 1
Set-WSManInstance -ResourceURI winrm/config/Listener `
-SelectorSet @{ Address = '*'; Transport = 'HTTPS' } `
-ValueSet @{ CertificateThumbprint = $cert.Thumbprint }Then import the new .cer file on your workstation, test the connection, then delete the old certificate on both sides.
Remove everything
Remove-WSManInstance -ResourceURI winrm/config/Listener -SelectorSet @{ Address = '*'; Transport = 'HTTPS' }
Remove-NetFirewallRule -Name 'WinRM-HTTPS-Admin'Troubleshooting
The port does not respond
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.Check in this order:
- Your current public address is indeed the one in the
WinRM-HTTPS-Adminrule. - The listener exists and port
5986is listening on the server. - The host name points to the right address:
Resolve-DnsName srv.your-domain.com. - The firewall configurable from your plan's console, if you use one, allows this port.
Unknown certification authority
The SSL certificate is signed by an unknown certificate authority.The certificate is not trusted by your workstation. Import the .cer file into Cert:\LocalMachine\Root from an administrator PowerShell, and check that it is indeed the certificate used by the listener.
The name does not match the certificate
The SSL certificate contains a common name (CN) that does not match the hostname.Connect using the exact name in the certificate, not the IP address or another alias.
Expired certificate or revocation cannot be checked
The SSL certificate is expired.
The SSL certificate could not be checked for revocation.Renew the expired certificate. For the second message, make sure your workstation can reach the authority's revocation servers.
The client asks for HTTPS or TrustedHosts
The WinRM client cannot process the request. If the authentication scheme is different from Kerberos, or if the client computer is not joined to a domain, then HTTPS transport must be used or the destination machine must be added to the TrustedHosts configuration setting.The -UseSSL parameter is missing from your command. Do not add the server to TrustedHosts: that would only hide the lack of verification of its identity.
Access denied
Access is denied.Check the server name, the account and the password. By default, only members of the Administrators group can connect.
A local administrator account other than the built-in account can also be refused because of UAC remote restrictions. Preferably use the built-in Administrator account or a domain account. The LocalAccountTokenFilterPolicy registry value lifts this restriction, but for all local accounts on the machine: only enable it if you understand the consequences.
Listener creation fails
Cannot create a WinRM listener on HTTPS because this machine does not have an appropriate certificate.This message appears notably with winrm quickconfig -transport:https: use New-WSManInstance as in step 3. Also check that the certificate has not expired and that its CN exactly matches Hostname.
If an HTTPS listener already exists, delete it with Remove-WSManInstance, then recreate it.
Access denied to another machine from the session
Your password is not passed on to the remote server, which therefore cannot authenticate on your behalf to a network share or another server. This is known as the "second hop" problem. Run the command directly on the target machine, or pass explicit credentials to the command concerned.