title: Setting Windows Server Password in EC2 User Data
body: <p>I'd like to set a Windows Server 2012 R2 Administrator password in the AWS EC2 User Data, but something about what I'm doing isn't working.</p>
  
  <p>I'm launching the instance with the following value for the User Data:</p>
  
  <pre><code>&lt;powershell&gt;
  $user = [adsi]"WinNT://localhost/Administrator,user"
  $user.SetPassword("Tm8LgmjBTigXq8PYifGG@RGQaXoqzT")
  $user.SetInfo()
  &lt;/powershell&gt;
  </code></pre>
  
  <p>I'll use a different password for prod, but wanted to make sure I meet Windows password requirements for now.</p>
  
  <p>As far as what AMI, I'm using, I started off with a trivial <a href="http://packer.io" rel="nofollow">Packer</a> build based on the Amazon-provided Windows Server 2012 R2 AMI.  All this Packer build does right now is add a directory and then outputs the AMI ID it created.  I then launch a new instance from that AMI.</p>
  
  <p>But when I RDP into the instance, I continue to receive the error <code>The user name or password is incorrect. Try again.</code>.</p>
  
  <p>Here are the logs from EC2's "Get System Log":</p>
  
  <pre><code>2015/12/17 02:26:26Z: EC2ConfigMonitorState: 0
  2015/12/17 02:26:27Z: Windows sysprep configuration complete.
  2015/12/17 02:26:30Z: AMI Origin Version: 2015.10.26
  2015/12/17 02:26:30Z: AMI Origin Name: Windows_Server-2012-R2_RTM-English-64Bit-Base
  2015/12/17 02:26:30Z: OS: Microsoft Windows NT 6.3.9600
  2015/12/17 02:26:30Z: OsVersion: 6.3
  2015/12/17 02:26:30Z: OsProductName: Windows Server 2012 R2 Standard
  2015/12/17 02:26:30Z: OsBuildLabEx: 9600.18066.amd64fre.winblue_ltsb.150928-1002
  2015/12/17 02:26:30Z: Language: en-US
  2015/12/17 02:26:30Z: EC2 Agent: Ec2Config service v3.10.442
  2015/12/17 02:26:32Z: Message: Waiting for meta-data accessibility...
  2015/12/17 02:26:32Z: Message: Meta-data is now available.
  2015/12/17 02:26:35Z: AMI-ID: ami-0cd7c86d
  2015/12/17 02:26:35Z: Instance-ID: i-9da97047
  2015/12/17 02:26:40Z: Driver: AWS PV Network Device v7.3.2.0
  2015/12/17 02:26:40Z: Driver: AWS PV Storage Host Adapter v7.3.2.0
  2015/12/17 02:26:40Z: Ec2SetPassword: Disabled
  2015/12/17 02:26:41Z: RDPCERTIFICATE-SUBJECTNAME: WIN-B5RLUMJ651G
  2015/12/17 02:26:41Z: RDPCERTIFICATE-THUMBPRINT: A03F21FCE336140DA63828E3D61FB1274C6CF26E
  2015/12/17 02:26:44Z: Message: Windows is Ready to use
  2015/12/17 02:26:52Z: Info EC2Config configuration: status:3; region:us-west-2; iam:0; authz:0
  2015/12/17 02:26:52Z: SSM Config: status:Inactive; iam:No; ErrorMessage:[[Unable to find credentials]]; RequestId:; ErrorCode:; ErrorType:Sender; StatusCode:0
  Close
  </code></pre>
  
  <p>Would love some guidance from any Windows experts out there!</p>
  
  <p><strong>Update #1:</strong> I've taken a new approach.  It appears AWS has a service called the <a href="http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/UsingConfig_WinAMI.html" rel="nofollow">EC2ConfigService</a> which can be used to enable password generation from custom AMI's.  Using Packer, I replaced the file <code>C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml</code> with one where the setting for <code>Ec2SetPassword</code> is <code>Enabled</code>, but it still doesn't seem to make a difference.  I'll look for online examples of changing this to see if I can find any.</p>