Skip to content

Instantly share code, notes, and snippets.

@tomfanning
Created October 26, 2017 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomfanning/718374d32cbef0e11c2aa003b140c145 to your computer and use it in GitHub Desktop.
Save tomfanning/718374d32cbef0e11c2aa003b140c145 to your computer and use it in GitHub Desktop.
Recipe for getting a prompt on a stock Windows EC2 instance
In userdata on the target:
<powershell>
$admin = [adsi]("WinNT://./administrator, user")
$admin.PSBase.Invoke("SetPassword", "SufficientlyC0mplexPasswordHere!")
Invoke-Expression ((New-Object System.Net.Webclient).DownloadString('https://gist.githubusercontent.com/tomfanning/19a983ad793e63d68117bd90bd57e02b/raw/8508a56fd5eb0456e2aa34a278cb7e6fbafe9dd8/configure-windows-remoting-ec2.ps1'))
</powershell>
Also ensure a security group is applied which opens port 5986.
Start the VM. Can take a few minutes for the script to sort itself out.
Then from a bastion host:
$hostName="ec2-1-2-3-4.eu-west-2.compute.amazonaws.com" #
$winrmPort = "5986"
$password = ConvertTo-SecureString "SufficientlyC0mplexPasswordHere!" -AsPlainText -Force
$cred= New-Object System.Management.Automation.PSCredential ("administrator", $password )
$soptions = New-PSSessionOption -SkipCACheck
Enter-PSSession -ComputerName $hostName -Port $winrmPort -Credential $cred -SessionOption $soptions -UseSSL
ta da! prompt.
Now need to get it running on standard HTTPS port, through authenticated proxy...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment