Skip to content

Instantly share code, notes, and snippets.

@timyhac
Created June 22, 2016 04:50
Show Gist options
  • Save timyhac/ba578e4cc9cb91000592d789d66f34c8 to your computer and use it in GitHub Desktop.
Save timyhac/ba578e4cc9cb91000592d789d66f34c8 to your computer and use it in GitHub Desktop.
Create Windows EC2 instance and remote desktop to it
Function Start-Countdown
{ <#
.SYNOPSIS
Provide a graphical countdown if you need to pause a script for a period of time
.PARAMETER Seconds
Time, in seconds, that the function will pause
.PARAMETER Messge
Message you want displayed while waiting
.EXAMPLE
Start-Countdown -Seconds 30 -Message Please wait while Active Directory replicates data...
.NOTES
Author: Martin Pugh
Twitter: @thesurlyadm1n
Spiceworks: Martin9700
Blog: www.thesurlyadmin.com
Changelog:
2.0 New release uses Write-Progress for graphical display while couting
down.
1.0 Initial Release
.LINK
http://community.spiceworks.com/scripts/show/1712-start-countdown
#>
Param(
[Int32]$Seconds = 10,
[string]$Message = "Pausing for 10 seconds..."
)
ForEach ($Count in (1..$Seconds))
{ Write-Progress -Id 1 -Activity $Message -Status "Waiting for $Seconds seconds, $($Seconds - $Count) left" -PercentComplete (($Count / $Seconds) * 100)
Start-Sleep -Seconds 1
}
Write-Progress -Id 1 -Activity $Message -Status "Completed" -PercentComplete 100 -Completed
}
$instance = (aws ec2 run-instances --image-id ami-5bf72138 --count 1 --instance-type t1.micro --key-name SAVED_KEY --security-groups launch-wizard-1) | Out-String | ConvertFrom-Json
$ipaddress = (aws ec2 describe-instances --query "Reservations[*].Instances[*].PublicIpAddress" --output=text)
Start-Countdown -Seconds (4*60) -Message "Waiting 4 minutes for instance to be ready"
$aws_output = (aws ec2 get-password-data --instance-id $instance.Instances[0].InstanceId --priv-launch-key "C:\path\to\key.pem") | Out-String | ConvertFrom-Json
$aws_output.PasswordData | clip.exe
Write-Host "Password: " +$Password
Write-Host Password copied to clipboard
mstsc.exe /v $ipaddress
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment