Skip to content

Instantly share code, notes, and snippets.

@andrewiankidd
Last active June 22, 2021 06:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewiankidd/f47e8bc7d6a2cc68711e8d3e01850b8a to your computer and use it in GitHub Desktop.
Save andrewiankidd/f47e8bc7d6a2cc68711e8d3e01850b8a to your computer and use it in GitHub Desktop.
Enable WinRM HTTPS via powershell
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