Automate retrieving password from Ec2 windows instance that was launched from custom AMI

384 Views Asked by At

When the instance is launched from the custom AMI I could not retrieve password for the launched instance. This issue and resolution is discussed here and it worked.
These are the manual steps I performed:

  1. Open the Amazon EC2 console, and then connect to the original Windows EC2 instance using Remote Desktop Protocol (RDP).
  2. From the Windows Start menu, do the following:
    For Windows Server 2008 through Windows Server 2012 R2, open EC2ConfigService Settings, and then choose the Image tab.
    For Windows Server 2016 or later, open EC2 Launch Settings.
  3. For Administrator Password, choose Random.
  4. Select Shutdown without Sysprep *.
  5. Select Yes.
  6. Open the Amazon EC2 console, and then select Instances.
  7. Wait until the instance state changes to Stopped, and then choose your instance.
  8. Select Actions, Image, Create image. For Image name, enter a name. (Optional) For Image description, enter a description.
  9. Choose Create image.

I wanted to know if steps from 1 to 5 can be automated? The source instance has the following scripts, and wondering if any of these script will do the trick, if yes, then what parameter I need to pass

"C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\SendWindowsIsReady.ps1 -Schedule",  
"C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeInstance.ps1 -Schedule",  
"C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\SysprepInstance.ps1 -NoShutdown"  
0

There are 0 best solutions below