Skip to content

Instantly share code, notes, and snippets.

@tjmichael81
Last active October 2, 2015 14:03
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 tjmichael81/ed5501bba798b2fe9341 to your computer and use it in GitHub Desktop.
Save tjmichael81/ed5501bba798b2fe9341 to your computer and use it in GitHub Desktop.
AWS - Create instance image w/ Powershell
# Task Scheduler run as powershell -f "<path to script>"
# General Script Variables
$serverName = "<server name>"
$date = Get-Date -UFormat "%m/%d/%Y"
$imageName = "$serverName $date"
# Retrieve instance ID from EC2 Instance Metadata
$instanceID = (New-Object System.Net.WebClient).DownloadString("http://169.254.169.254/latest/meta-data/instance-id")
# Create instance image. -NoReboot:$false stops the instance prior to creating the image
New-EC2Image -InstanceId $instanceID -Name $imageName -Description "Test Server Image" -NoReboot:$false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment