Useful Administrative Scripts

On this page is a few simple scripts I've worked on and probably something all network admins should have in some form. It will make life easier trust me.

  1. Backup Files for Workstation Rebuild/Migration
  2. Add a list of users to Active Directory from a text file

Backup Files for Workstation Rebuild/Migration

Here's a script I wrote while working as an intern at IND Corp. It's pretty straight forward. What it does is copy files from one location to another by file extension. It also creates a list of printers that are installed and backs up all local user's Favorites folder.

For i = 0 To Ubound(arrFileTypes)
	WScript.Echo "Copying all " & arrFileTypes(i) & " files..."
	Log arrFileTypes(i) & " files"
	Log "-------------------------------------------------------------------"
	Set objScriptExec = objShell.Exec("xcopy " & source & "\*." & arrFileTypes(i) & " c:\back /C /Y /S")
	Log objScriptExec.StdOut.ReadAll

The loop that copies all the files

If you look at the snippet above you can see it just uses the built in program called xcopy to copy all the files from the source to the destination. The script will actually use input boxes to retrieve the source and destination.

This script dose have a few limitations. You cannot set the source to say C: and the destination to C:\backup. This is because of how xcopy works. It will recursively scan C: and it can't copy the files to somewhere that it will be searching for files. Typically, as an administrator you should be backing up to a network share or external drive anyway so this isn't that big of a deal.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
	& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
	("Select * from Win32_Printer")

' loop through printers and output to file
WScript.Echo "Creating list of printers..."
Log "Installed Printers"
Log "-------------------------------------------------------------------"
For Each objPrinter in colInstalledPrinters

Query WMI for the installed printesr

Above you see how the script looks at WMI for all the installed printers and just uses the Log function to output it to the output file. Which in this case is called _output.txt and stored in the backup destination. This file will tell you everything that was backed up and give you the printer list.

Downloads: Sample Output, Script Source, Basic Instructions

Add a list of users to Active Directory from a text file


  • Adds users from a specified text file
  • creates a log file to keep track of what is happening
  • Writes to Event Log on successful creation of a user
  • Automatically generates config file if none is present (must be edited to use properly)
  • Easy to configure for people who don't know anything about scripting
  • Ability to assign what OU to store the user in
  • Various options for configuring how a user is added
  • Checks for username conflicts then adds integer to create a unique username

This script will save you tons of time when your company decides to hire a whole bunch of people. Chances are your company will have everything about the new hires in a database. Well with a simple database query you can create a comma separated list to be used with this script. I put a lot of time into this one to make it the most user friendly (well for people that know what they're doing) as possible. Upon first run it creates a configuration file. Which looks something like this:

# signifies a comment

#Path to text file containing user information

#Path to OU where new users are added, read README.txt for more info
ou_path=ou=OU, ou=To, ou=Path

#Fully Qualified Domain Name

#Default password for new users

#force user to change password at next logon

#create account disabled

This really allows it to be used on any network since nothing is hard coded. All the settings are loaded into a dictionary object and called upon when needed.

There's also some nice error checking built in that will test to see if a username is already taken. If it is it tries appending an integer and increases it by 1 until it finds a unique username. The naming scheme I used was first initial + last name. It also fills in the users address and phone number.

Downloads: Read me first!, Script Source, Example User List

Back to my projects