Last active
June 22, 2021 06:29
-
-
Save andrewiankidd/f47e8bc7d6a2cc68711e8d3e01850b8a to your computer and use it in GitHub Desktop.
Enable WinRM HTTPS via powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ($fqdn) | |
if ($fqdn -eq $null){ | |
#lots of assuming going on here | |
$zone = ".westeurope.cloudapp.azure.com" | |
$fqdn = "$env:computername$zone" | |
} | |
##enable winrm | |
Write-Host "------Enabling WinRM (HTTP)" | |
winrm quickconfig -q | |
Write-Host "------Genning Thumbprint" | |
#get thumbprint | |
$thumbprint = (New-SelfSignedCertificate -certstorelocation cert:\localmachine\my -dnsname $fqdn -NotAfter (Get-Date).AddMonths(36)).Thumbprint | |
Write-Host "------Proceeding with following details" | |
#create cert | |
Write-Host fqdn: $fqdn, thumbprint: $thumbprint | |
$cmd = 'winrm create winrm/config/listener?Address=*+Transport=HTTPS `@`{Hostname=`"$fqdn`"`; CertificateThumbprint=`"$thumbprint`"`}' | |
Write-Host "------Enabling WinRM (HTTPS)" | |
Invoke-Expression $cmd | |
Write-Host "------Making Firewall rule" | |
#poke hole in firewall | |
& netsh advfirewall firewall add rule name="winRM HTTPS" dir=in action=allow protocol=TCP localport=5986 | |
Write-Host "------Testing WinRM" | |
& test-wsman $fqdn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment