# Change Windows 'administrator' password upon first login of a new VM

**URL:** <https://forum.ansible.com/t/change-windows-administrator-password-upon-first-login-of-a-new-vm/38132>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [June 20, 2023, 5:47pm UTC](https://forum.ansible.com/t/change-windows-administrator-password-upon-first-login-of-a-new-vm/38132 "2023-06-20T17:47:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlemons](https://avatars.discourse-cdn.com/v4/letter/t/edb3f5/32.png) [@tlemons](https://forum.ansible.com/u/tlemons)\
**Post date:** [June 20, 2023, 5:47pm UTC](https://forum.ansible.com/t/change-windows-administrator-password-upon-first-login-of-a-new-vm/38132/1 "2023-06-20T17:47:24Z")

</div>

Hi - my team has an Ansible automation that deploys and configures a new Windows Server system in our vSphere-based lab environment. It uses govc to deploy an .ova created within our company that has a secure password for the ‘administrator’ account, and the ‘administrator’ account is set to force a password change on first login. I want to automate the password change in our Ansible workflow. After ova deployment, the network settings have not yet been applied.

I’ve tried using the vmware\_vm\_shell module with these values:

- name: “Set new administrator account password”  
local\_action:  
module: vmware\_vm\_shell  
hostname: “{{ management\_vcenter\_ip }}”  
username: “{{ management\_vcenter\_user }}”  
password: “{{ management\_vcenter\_password }}”  
validate\_certs: False  
datacenter: “{{ datacenter }}”  
vm\_id: “{{ vm\_name }}”  
vm\_username: “{{ vm\_admin }}”  
vm\_password: “{{ vm\_password }}”  
vm\_shell: “C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe”  
vm\_shell\_args: " -command Set-LocalUser -Name administrator -Password {{vm\_new\_password}}"  
vm\_shell\_cwd: “C:\Windows\Temp”

but am seeing this unhelpful response:

TASK [deploy-windowssql : Set new administrator account password] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [[ldpdd192.hop.lab.emc.com](http://ldpdd192.hop.lab.emc.com) → localhost]: FAILED! =\> {“changed”: false, “msg”: “A general system error occurred: vix error codes = (1, 0).\n”}

Am I using vmware\_vm\_shell or the Powershell Set-LocalUser command incorrectly? Or is there a better way to change the ‘administrator’ password on a VM that is running but is not yet network-accessible?

Thanks!

---

<div class="post-metadata">

**Author:** ![tlemons](https://avatars.discourse-cdn.com/v4/letter/t/edb3f5/32.png) [@tlemons](https://forum.ansible.com/u/tlemons)\
**Post date:** [July 3, 2023, 3:47pm UTC](https://forum.ansible.com/t/change-windows-administrator-password-upon-first-login-of-a-new-vm/38132/2 "2023-07-03T15:47:14Z")

</div>

I’ve spent more hours on this, and I think a cleaner way to change the password of the administrator account is by using the command:

net user administrator ‘password’

but I’m having trouble with getting this command to work. I think the problem is with the ‘vm\_shell’ value, as I’m not sure which shell to use.

Thoughts?

Thanks  
tl

---

<div class="post-metadata">

**Author:** ![tlemons](https://avatars.discourse-cdn.com/v4/letter/t/edb3f5/32.png) [@tlemons](https://forum.ansible.com/u/tlemons)\
**Post date:** [August 2, 2023, 7:07pm UTC](https://forum.ansible.com/t/change-windows-administrator-password-upon-first-login-of-a-new-vm/38132/3 "2023-08-02T19:07:13Z")

</div>

A colleague helped me with the knowledge that the customization ‘existing\_vm’ key needed to be provide with a value of True, and the ‘state’ key needed a value of ‘present’. The module below does set the ‘administrator’ password when the account is set for ‘change password on first login’:

- name: “Set a new administrator account password and power on the VM”  
community.vmware.vmware\_guest:  
hostname: “{{ management\_vcenter\_ip }}”  
username: “{{ management\_vcenter\_user }}”  
password: “{{ management\_vcenter\_password }}”  
datacenter: “{{ datacenter }}”  
cluster: “{{ cluster }}”  
name: “{{ vm\_name }}”  
state: present  
networks:
- name: “{{ vm\_network }}”  
validate\_certs: False  
wait\_for\_customization: true  
wait\_for\_ip\_address: true  
customization:  
password: “{{ vm\_password }}”  
existing\_vm: True  
delegate\_to: localhost
