Tired of doing repetitive task... I need a script!

Hey all,
The place i’m currently has some cool machines that gets setup by me and sent to the company’s clientele. Boring part is… setting them up, all the same: same procedure, same settings, same programs install. Tried proposing them to just clone the images, but alas, so i was thinking maybe i should just make a script that takes away most of the clicks i have to perform on each machine. But i have no idea where to start.
So anyone here wiling to give a hand?

It really depends what you need to install… do you have the setup files locally? i.e. do you just copy them onto the hard drives and execute them one by one? If so you can just write a .bat that executes the setup files in order.

You can also optimise that to do a silent install (i.e. all default settings and no dialogues to click through). You’d have to check for each setup what kind of installer they are using (.msi or .exe, Innosetup vs NSIS etc) and what the respective flags are for that, but generally it is possible for most installers to do a silent install.

If you are also installing third-party software you can use something like Ninite to accomplish something similar, or you can go wild with chocolatey, although you need a powershell module for that.

1 Like

the most time consuming part are the settings frankly, like renaming the computer, adding a registry key, add a user environement variable, etc… after all that is done comes installing things

1 Like

I’ve never done this myself, but I guess this is a good start:

https://www.windows-commandline.com/change-computer-name-command-line/

Set it up on a test machine, export the key, you get a .reg file. You can import that using regedit.exe exportedregfile.reg (I think reg import file.reg also works), assuming the value is always the same.
If it is not always the same and depends on any of the other set values or whatever you can create the .reg file on the fly (see here) and then import it.

See here:

2 Likes

An alternative to installing the software, all-be-it scripted onto each machine may be to do it once, run sysprep and then take an image of the hard disk. After that you just write the image to each new machine.

Downside is the images can go stale and you need to figure out how you are going to write the image.

2 Likes

does sysprep bring the same issues as i’d get when making a clone image like overwritting the Windows product key?

Essentially yes, but that part can be scripted. At the place that I used to work (Pharmacy Software firm) we basically used sys prep to create images for the hardware and versions of MS Windows that we supported. From there, we would install the purchased softwares through PowerShell scripts. Since we wrote our own software, we used the MSI packagers and built our own flags to basically pass all of the required customer configuration information at install time so that the information could be setup for the customer. I even modified it to take in a text file that was generated via a PowerShell script that implemented WinForms so that you could look at all the information before walking away to let the system do its thing.

May need more information to assist in that part, but basically, if you are MS Windows and you are not using PowerShell, you really are doing yourself a disservice.

1 Like

Yeah but the problem here is that we receive our PCs from Siemens, they with an already active OEM Windows key, then we do the first boot, setup everythig that needs to be setup, install everything that needs to be installed, back it up, put it back in the box, and send it to the rig where it will be installed and shipped to the client.
One big issues, which i tried when i decided to restore a backup image on a new system, is that the new system would get the key of the of the cloned system, and when i tried to change product key and put in it’s own, i need to plug it to the internet to confirm the activation. But we are instructed to never plug those systems to the web. So restore that machine to factory settings and prep it by hand as always :sweat_smile:

Your use case is screaming for Powershell and Chocolatey. Install programs with Chocolatey, change settings via Powershell.

Rename-Computer - docs

New-Item -Path HKCU:\path\to\key - info

New-LocalUser or New-ADUser - docs

[System.Environment]::SetEnvironmentVariable() - info


Try running the commands by hand in Powershell at first, then once you set them up the way you like, stick them in a .ps1 file, which you can then run with two clicks.

6 Likes

Okay, so the problem is that you are not using MS Windows Enterprise Editions. So, you can pull the individual MS Windows licenses with power shell. Basically backup the current system, place your sysprep image on the box, put in the license of the backedup system and see id it works. If ao them basically, everything that we suggested will work for you, but you will need to pull the license key before letting the rest of the automation roll.

1 Like

Just checked: they all mount Windows 10 Enterprise LTSB, so what does it entail in this case?

You should then be able to used an enterprise license when laying down the sysprep image and it should not yell at you about it. The catch is that the enterprise key will be the same for all dependong on how you allocate your CALs from MS.

Faced the same problem you have.
I made two separate powershell scripts for that.
One that adds the computer to the local domain and renames it while also pushing it into the correct ou
The second one to install a bunch of software after reboot

You should be all set with powershell honestly

You can even use those scripts to install on remote mashines if you have psremoting enabled

1 Like

Okay, could try that too, as long as Chocolatey can be set to uninstall itself once it’s done.
also i’ll take the chance to put all the task that i have to perform everytime:

  • Rename the computer (have 2 names, for 3 systems that all have the same hardware, eg server1 and server2, and the third is a backup to server1 that will have the same name)
  • add an evironment variabe
  • enable remote connection to anyone and enable remote asistance
  • add the reg key
  • set date and timezone to auto and change the ntp to another server we have
  • rename the 4 ethernet
  • enable every setting in advanced file sharing in public, private and all
  • delete partition D and extend C
  • replace the host file
  • map a netword drive
  • (finally) install software

Yeah, It didn’t yell at me when i restored the image, it only did when i tried to give it back it’s license cause it had to call home to check before confirming the key change.

what i wanted to avoid, cause i don’t want them to cause issue once the rigs are deployed

Possible in Powershell, see my previous post for command to research.

Change two registry keys in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Remote Assistance

fAllowToGetHelp and fAllowFullControl

Change either directly with powershell, or create a .reg file and run that with powershell.

Set-TimeZone and for NTP setup use w32tm.exe

Rename-NetAdapter

I think at least some of these are firewall rules under the hood. Change firewall rules in powershell via Set-NetFirewallRule

Delete-Parition and Resize-Parition

Set-Content

New-PSDrive -Persist - the persist means that it shows up in windows explorer and sticks arround, without persist it disappears as soon as you close the powershell window.


Delete C:\ProgramData\chocolatey, Delete the environment variables ChocolateyInstall, ChocolateyToolsLocation, ChocolateyLastPathUpdate. Remove C:\ProgramData\chocolatey\bin from %PATH%.

This will also uninstall any software that comes from *.portable packages.

3 Likes

That is not actually a problem, as long as your company holds the paper work for the license. This is how the Microsoft Certified Partners thing works with Enterprise licenses and CALs.

If your organization will not be the holder of such paper work, then you would apply for an Enterprise license for each customer. The machines will have the same license but it will belong to that organizations

Even if the above is out of the question, you should be able to make an image for each customer using server 1, and the other two servers can be clones of that one machine and they should accept the license with no issue. You can also just use the call into the MS automated system and register them that way.

But even without using sysprep, power shell will take care of everything you are trying to do without needing to create images.

Will try these as soon as some new systems arrive, already got everything boxed and ready to be shipped for this week :joy:

1 Like

mmmmhhh okay, interesting will keep this in mind and try it on a server1 and it’s backup server to test


It’s been a while but i finally got a full system to test this

1 Like