Skip to content

Instantly share code, notes, and snippets.

@bobalob
Created December 21, 2016 15:36
Show Gist options
  • Save bobalob/6a406b93718eea8f04936179b2b3623f to your computer and use it in GitHub Desktop.
Save bobalob/6a406b93718eea8f04936179b2b3623f to your computer and use it in GitHub Desktop.
$RemoteHostName = $ENV:ComputerName
$ComputerName = $ENV:ComputerName
Write-Host "Setup WinRM for $RemoteHostName"
$Cert = New-SelfSignedCertificate -DnsName $RemoteHostName, $ComputerName `
-CertStoreLocation "cert:\LocalMachine\My"
$Cert | Out-String
$Thumbprint = $Cert.Thumbprint
Write-Host "Enable HTTPS in WinRM"
$WinRmHttps = "@{Hostname=`"$RemoteHostName`"; CertificateThumbprint=`"$Thumbprint`"}"
winrm create winrm/config/Listener?Address=*+Transport=HTTPS $WinRmHttps
Write-Host "Set Basic Auth in WinRM"
$WinRmBasic = "@{Basic=`"true`"}"
winrm set winrm/config/service/Auth $WinRmBasic
Write-Host "Open Firewall Port"
netsh advfirewall firewall add rule name="Windows Remote Management (HTTPS-In)" dir=in action=allow protocol=TCP localport=$WinRmPort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment