Skip to content

Instantly share code, notes, and snippets.

@andrewiankidd
Last active June 22, 2021 06:29
Show Gist options
  • Select an option

  • Save andrewiankidd/f47e8bc7d6a2cc68711e8d3e01850b8a to your computer and use it in GitHub Desktop.

Select an option

Save andrewiankidd/f47e8bc7d6a2cc68711e8d3e01850b8a to your computer and use it in GitHub Desktop.

Revisions

  1. andrewiankidd revised this gist Jan 9, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion enableWinRM.ps1
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ winrm quickconfig -q

    Write-Host "------Genning Thumbprint"
    #get thumbprint
    $thumbprint = (New-SelfSignedCertificate -certstorelocation cert:\localmachine\my -dnsname $fqdn).Thumbprint
    $thumbprint = (New-SelfSignedCertificate -certstorelocation cert:\localmachine\my -dnsname $fqdn -NotAfter (Get-Date).AddMonths(36)).Thumbprint

    Write-Host "------Proceeding with following details"
    #create cert
  2. andrewiankidd revised this gist Aug 15, 2017. No changes.
  3. andrewiankidd created this gist Aug 14, 2017.
    32 changes: 32 additions & 0 deletions enableWinRM.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    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