How to change windows password

we are using packer to build windows image. the base image is a qcow2 file with some pre-defined password. It works well until we are asked to change this password to something more complicated.

we then write a script to change password but found that packer still uses old password to connect which yields 401 and failed to shutdown the machine.

Are there any methods to work around this issue? thank you.

Hi @jshen28 Packer doesn’t have a way to reconfigure the communicator (WinRM or SSH) to reconnect given a username, password, or IP change. It is something we are looking into.

In the meantime, could you share the builder that you are using for building the Windows VM. Some of the builders via may offer an ability to skip the shutdown command step to help with this issue.

If the password change is happening in a provisioner have you tired issuing a shutdown command as part of the script?

Without going into too much details a common practice when changing passwords for a user is to run the password change script as the last provisioning step and include a shutdown command in the same script to bring the machine down - thinking maybe a scheduled shutdown for 3 seconds via the shutdown command.

I believe that as long as the provisioner executes successfully Packer will exit the connection and continue with a noop for the shutdown process since the machine has been halted.

Please let me know if this changes anything for you.

Hi @nywilken , thank you very much for your reply. I am using qemu plugin to build vm images. as to shutdown vm in the last step, I will try it and thank you for your advice!