Automating Windows 10 Installs

I hate repetitive tasks, but I love automating them. One of the most common tasks for me is installing Windows, so I sought to automate as much of that as I could. I just wanted to write about a custom command I made for my Windows 10 Answer File.

If you haven’t heard of Windows 10 Answer Files, you can read about them here. Long story short, they automate installs for things like Windows and Office. If you want to get make your own, you can easily get started by using a template from the unofficial Windows 10 Answer File Generator.

In my Answer File (I will now call it autounattend.xml) I automatically wipe the hard drive of the target computer, reformat it, add my company as the organization, name the initial user, set the language and time zone, enter the product key for Windows, add a basic password-less admin account, enable the Local Administrator account, set the Local Administrator password, and disables the temporary admin account.

After that things get fun.

I wanted to launch a prompt asking for the user to input a computer name, then name the computer and restart. Unfortunately documentation on this subject is incredibly scarce so I had to figure out a solution myself. Thankfully, I’m a stubborn person.

A couple limitations to autounattent.xml command capabilities:

  • Each command must be on a single line of code.
  • Each line of code can be no greater than 260 characters.
  • Local variables can not be set and used on the same line of code.

Ouch. Long story short, I found a solution: create a temporary container and set environment variables within that container, then close it. That way I can set a variable and use it on a single line of code.

<SynchronousCommand wcm:action="add">
          <CommandLine>cmd /V /C echo Computer name:&setlocal&set /p NewName=&powershell -Command "Add-Computer -domainname *********.com -ComputerName $env:computername -NewName $env:NewName -OUPath 'OU=Newly Configured Computers,OU=I. T.,DC=**********,DC=com'"&endlocal</CommandLine>
          <Description>Rename PC and Join Domain</Description>

From there, Group Policy installs Chrome and UltraVNC with the desired configuration, customizes firewall settings and allows RDP. All that to say, deploying new computers is now a very simple process. An hour saved is an hour earned, right?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s