<powershell>
# Set administrator password
net user Administrator SOMETHINGGOOD
wmic useraccount where "name='Administrator'" set PasswordExpires=FALSE
# First, make sure WinRM can't be connected to
netsh advfirewall firewall set rule name="Windows Remote Management (HTTP-In)" new enable=yes action=block
# Delete any existing WinRM listeners
winrm delete winrm/config/listener?Address=*+Transport=HTTP 2>$Null
winrm delete winrm/config/listener?Address=*+Transport=HTTPS 2>$Null
# Create a new WinRM listener and configure
winrm create winrm/config/listener?Address=*+Transport=HTTP
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="0"}'
winrm set winrm/config '@{MaxTimeoutms="7200000"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service '@{MaxConcurrentOperationsPerUser="12000"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
winrm set winrm/config/service/auth '@{Certificate="true"}'
winrm set winrm/config/client/auth '@{Basic="true"}'
winrm set winrm/config/client/auth '@{Certificate="true"}'
# Configure UAC to allow privilege elevation in remote shells
$Key = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System'
$Setting = 'LocalAccountTokenFilterPolicy'
Set-ItemProperty -Path $Key -Name $Setting -Value 1 -Force
# Configure and restart the WinRM Service; Enable the required firewall exception
Stop-Service -Name WinRM
Set-Service -Name WinRM -StartupType Automatic
netsh advfirewall firewall set rule name="Windows Remote Management (HTTP-In)" new action=allow localip=any remoteip=any
Start-Service -Name WinRM
</powershell>
Here is my user_data.txt file from the line "user_data_file": "scripts/user_data.txt.
As you can see, I want to be able to use a predetermined password.
==> amazon-ebs: Force Deregister flag found, skipping prevalidating AMI Name
171
amazon-ebs: Found Image ID: ami-0eb7fbcc77e5e6ec6
172
==> amazon-ebs: Creating temporary keypair: packer_5f720690-c3aa-4a5b-103b-b244e5cfaf67
173
==> amazon-ebs: Creating temporary security group for this instance: packer_5f720692-6518-386c-fcfb-64088f3bdde8
174
==> amazon-ebs: Authorizing access to port 5986 from [
0.0.0.0/0] in the temporary security groups...
175
==> amazon-ebs: Launching a source AWS instance...
176
==> amazon-ebs: Adding tags to source instance
177
amazon-ebs: Adding tag: "Name": "Packer Builder"
178
amazon-ebs: Instance ID: i-076f324e8ca7a0f28
179
==> amazon-ebs: Waiting for instance (i-076f324e8ca7a0f28) to become ready...
180
==> amazon-ebs: Waiting for auto-generated password for instance...
181
amazon-ebs: It is normal for this process to take up to 15 minutes,
182
amazon-ebs: but it usually takes around 5. Please wait.
183
==> amazon-ebs: Error waiting for password: retry count exhausted. Last err: Error retrieving auto-generated instance password: UnauthorizedOperation: You are not authorized to perform this operation. Encoded authorization failure message: