Search code examples
windowspowershellserverwindows-server

Auto set password at initial boot on Windows Server


I setup virtual servers with Windows Server 2008/2012. I want to automate the password setting process for the windows guest.

My script would run like:

bash setupwindows.sh <kvmid> <password>

Then setupwindows.sh would mount the LVM, place the powershell script into the autostart directory and start the server.

I can change the password over windows cmd with

net user Administrator password

My question is: in which directory at the windows guest i need to place the powershell script to get it started on boot, without an user to be logged in?


Solution

  • I think the problem here is that you're approaching this with a linux/Bash style approach, which can lead you around in circles big time when trying this in Windows, as the two platforms have inherent differences.

    If you want to set your password at build time, and your machine is on a domain, then use Group Policy to set the default Admin Password using the setting found under Computer Configuration -> Expand Preferences -> Control Panel -> Local Users and Groups -> New - Local User -> Select Update as the action -> type Administrator into the User name text box.

    If you're not on a domain, then the best tool to use is the Windows System Image Manager, which comes as part of the Windows Automated Install Kit. You use this to open up a Windows Install Image (.wim) and select the accompanying unattend.xml which is used to automate the Windows Install.

    The value you want to change using SIM will be found under : Microsoft-Windows-Shell-Setup | UserAccounts | AdministratorPassword

    Here you can set the default admin password to whatever you wish.

    You could do this with a script, using the net use syntax, but the problem there is triggering the script to run. In my opinion, these two methods here represent the best approach to solving this problem.