Batch Scripting

Posted
Comments None

Batch scripting, the age old realm of the @0l 5kr1pt k1dd13, has become a friend to me in my current role.

I’ve been doing a lot of PC building in this role, today alone I’ve built 16 new computers. The build process was simple enough when I started but there was a lot of manual processing. It used to be as follows:

  1. Unbox PC and plug it in in the build room
  2. Power on and boot from the USB Drive that we install our Image from
  3. Wipe all the vendor’s partitions and hit install
  4. Windows installs itself and configures the Admin user
  5. On first boot it installs a couple of required applications and then presents a script to set the Hostname as per the asset tag on the machine
  6. On second boot it installs a few more applications and then we run a script to join it to the domain in the required OU
  7. Once it is on the domain SCCM will “automatically” deploy some further applications and the system is mostly ready to go


From step 7 it is possible to deploy the machine however a lot of the building I’ve been doing is for the Labs and they require some extra software to be installed that isn’t part of the SOE. This is where my Batch scripting comes into play. There are up to 5 applications that need to be installed on each machine in the lab. To provide for some redundancy I’ve just installed everything on to all machines that way anyone can sit at every computer and complete their tasks.

The process to install each application used to be as follows:

  1. Navigate to network share
  2. Find first application folder
  3. Run Installer1 – having to click the Ok to install prompt half way through
  4. Run Installer2 – also having to click the Ok to install prompt half way through
  5. Copy a file from application folder to the Program Files folder on the PC
  6. Run a .reg file to add some entries to the registry
  7. Find second application folder
  8. Run the batch script that someone had prepared
  9. Find third application folder
  10. Run batch script that someone else had prepared
  11. Copy files from application folder to the Program Files\Common folder
  12. Run regsvr32 on the copied files
  13. Find fourth application
  14. Install application – clicking Ok to install when prompted
  15. Find fifth application – decide between MS Office or OpenOffice and install


As you can see, there is far to much clicking involved in the process and having to do it dozens of times a day leads to mistakes being made. Some of the applications already had a basic batch file that would install multiple components so I got it in my head that I could expand on those batch files to create my own to automate the process a bit further. What started as a simple script has turned into a behemoth script system with multiple batch files and a prettified menu system. Given that three weeks ago I knew almost nothing of scripting to today where I am now the expert on the team, it was a lot of fun to learn and it has made the whole process faster and easier.

Run Me

  • Options 1-4 are the applications that are required for lab PCs
  • Options 5-6 are scripts that install everything in Options 1-4 plus Option 6 installs the NTBackup Restore Utility, finds the bkf file from the old asset, creates a folder called OldComputerData on the C:\, copies the bkf file there, and then opens up the Restore Utility. It also copies a script to the OldComputerData folder that will move the restored user data from the OldComputerData folder to their new profile after they login for the first time.


7Office
  • Option 7 is another script that lets the user choose from MS Office 2010 or OpenOffice 3 depending on what the old asset had


8Printers
  • Option 8 is another script that is designed to allow the user to add Network Printers to the Computer instead of having to add them for each user when they sign into the machine. The Add Printer script was actually one of the first that I wrote after one of the other guys found the command to type to do it, I simplified and streamlined it


NotAdmin
  • Since pretty much everything that the scripts do requires running as an Admin I found a little function that would check for them and fail out if the Batch file wasn’t run with the correct privileges but someone complained that it wasn’t made clear enough so I added this section to better indicate the permissions requirement.


Imaging PCs is a boring, repetitive task. Having this little project to do between unpacking and packing computers and all that clicking has been immensely rewarding. I love learning things and I really love making things easier for myself. This mission has done both with the added bonus of having the rest of the team be genuinely impressed with the new installation methods.

Author
Categories ,

Comments

There are currently no comments on this article.

Comments

Enter your comment below. Fields marked * are required. You must preview your comment before submitting it.





← Older Newer →