Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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).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