Skip to content

Instantly share code, notes, and snippets.

@euyuil
Created October 21, 2016 10:18
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save euyuil/64d89b044721ddb14fafa2e87698b21d to your computer and use it in GitHub Desktop.
Save euyuil/64d89b044721ddb14fafa2e87698b21d to your computer and use it in GitHub Desktop.
WinRM: Enable WinRM and create an HTTPS listener with self-signed certificate.
Param ($DnsName)
$Cert = New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My -DnsName $DnsName -Verbose
$Password = ConvertTo-SecureString -String $DnsName -Force -AsPlainText -Verbose
Export-Certificate -Cert $Cert -FilePath .\$DnsName.cer -Verbose
Export-PfxCertificate -Cert $Cert -FilePath .\$DnsName.pfx -Password $Password -Verbose
$CertThumbprint = $Cert.Thumbprint
Enable-PSRemoting -Force -Verbose
Set-Item WSMan:\localhost\Client\TrustedHosts * -Force -Verbose
New-Item -Path WSMan:\localhost\Listener -Transport HTTPS -Address * -CertificateThumbPrint $CertThumbprint -Force -Verbose
Restart-Service WinRM -Verbose
New-NetFirewallRule -DisplayName "Windows Remote Management (HTTPS-In)" -Name "WinRMHTTPSIn" -Profile Any -LocalPort 5986 -Protocol TCP -Verbose
@hoangvietitvn
Copy link

thanks :3 3rd_place_medal:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment