Menu

3 Apr 2026

πŸ”Preparing WinRM on Windows Server over HTTPS for Automation (Port-5986)

WinRM over HTTPS (5986)

πŸš€ Introduction

In many enterprises, automation is no longer optional—it’s a necessity. Tools like Azure DevOps, Jenkins, and Ansible need a secure way to connect to Windows servers to:

  • ▶️ Start/stop services
  • πŸ“¦ Deploy applications
  • ⚡ Run PowerShell scripts
  • πŸ› ️ Perform maintenance tasks

This blog explains how to securely configure WinRM over HTTPS (port 5986) using an enterprise SSL certificate, and why this approach is production-ready.


πŸ“˜ What is WinRM?

WinRM (Windows Remote Management) is Microsoft’s standard way to remotely manage Windows servers.

It allows you to:

  • πŸ–₯️ Run PowerShell commands on remote servers
  • 🚫 Execute scripts without logging in via RDP
  • πŸ” Automate tasks securely

By default, WinRM works over HTTP (port 5985), which is not secure for production. That’s where WinRM over HTTPS (port 5986) comes in.


πŸ”„ High-Level Flow (How It Works)

Azure DevOps Console
        |
        |  
        |  
        v		
Azure DevOps Agent
        |
        |  πŸ”’ WinRM over HTTPS (5986)
        |  πŸ” Encrypted using SSL Certificate
        v
Target Windows Server

🏒 Real-World Use Case

✅ Scenario: Production Application Automation

You have:

  • 🧩 A Windows server hosting applications (WebSphere, services, schedulers)
  • πŸš€ An Azure DevOps pipeline
  • ⛔ No permission or policy to use RDP in production

You want to:

  • πŸ”„ Restart services
  • 🧹 Clear cache folders
  • πŸ“€ Deploy builds
  • πŸ€– Run scripts automatically

# ============================================================
# πŸ” WinRM over HTTPS (5986)
# πŸ“œ Enterprise SSL Certificate
# πŸ€– Secure credential-based automation
# ✅ Production-ready for Azure DevOps
# ============================================================

# Architecture:
# Azure DevOps Agent / Admin Host
#   → πŸ”’ WinRM over HTTPS (5986)
#   → πŸ–₯️ Target Windows Server (172.23.XX.XX)

# ============================================================
# πŸ”‘ Install SSL Certificate on Target Windows Server and execute below steps on POWERShell
# ============================================================

# Step 1: ✅ Verify WinRM Service is installed and running
Get-Service WinRM

# Step 2: πŸ” Check existing WinRM listeners (HTTP / HTTPS)
winrm enumerate winrm/config/Listener

# Step 3: πŸ“œ Verify SSL certificate availability in Local Machine store,
#     ✅ Note the thumbprint for certificate
Get-ChildItem Cert:\LocalMachine\My | Select Subject, Thumbprint, NotAfter

# Step 4: 🧾 Validate certificate usage (must support Server Authentication),
#     πŸ” Replace with your certificate thumbprint
$cert = Get-Item "Cert:\LocalMachine\My\2FF032E91A3CF086C251B12D3AFCB5D71"
$cert.EnhancedKeyUsageList | Select FriendlyName

# Step 5: πŸ” Create WinRM HTTPS listener using certificate thumbprint
$Thumb = "2FF032E91A3CF086C251B12D3AFCB5D71"
New-Item -Path WSMan:\LocalHost\Listener `
-Transport HTTPS `
-Address * `
-CertificateThumbprint $Thumb

# Step 6: ▶️ Enable PowerShell Remoting and ensure WinRM auto-starts
Enable-PSRemoting -Force
Set-Service WinRM -StartupType Automatic
Start-Service WinRM

# Step 7: πŸ”‘ Allow local admin credentials over WinRM
New-ItemProperty `
-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" `
-Name LocalAccountTokenFilterPolicy `
-Value 1 `
-PropertyType DWord `
-Force

# Step 8: ✅ Final validation of WinRM listeners check for listening *5986 Port
winrm enumerate winrm/config/Listener

# Step 9: 🌐 Firewall / NSG validation
# Ensure port 5986 is allowed

# Step 10: πŸ§ͺ Client-side connectivity test (use valid username/password)
Invoke-Command `
-ComputerName 172.23.XX.XX `
-UseSSL `
-Port 5986 `
-Credential (Get-Credential) `
-Authentication Negotiate `
-SessionOption (New-PSSessionOption -SkipCNCheck -SkipCACheck -SkipRevocationCheck) `
-ScriptBlock { hostname; whoami }

# ============================================================
# ✅ End of WinRM HTTPS Configuration
# ============================================================

No comments:

Post a Comment