$hostname = "windows-ad-01"
$certificate = New-SelfSignedCertificate `
-DnsName $env:COMPUTERNAME, $hostname `
-CertStoreLocation Cert:\LocalMachine\My
Get-ChildItem WSMan:\localhost\Listener |
Where-Object {
$_.Keys -contains "Transport=HTTPS" -or
$_.Keys -contains "Transport=HTTP"
} |
Remove-Item -Recurse -Force
New-Item `
-Path WSMan:\localhost\Listener `
-Transport HTTPS `
-Address * `
-CertificateThumbPrint $certificate.Thumbprint `
-Force
New-NetFirewallRule `
-DisplayName "WinRM HTTPS" `
-Direction Inbound `
-Protocol TCP `
-LocalPort 5986 `
-Action Allow `
-Profile Any