Video Transcript

Hi. This is Greg Shields and I am going to show you a scripting framework you can use to assist in automatically mapping printers whenever users switch between different Active Directory sites. You can see here in the upper right hand corner of this screen I have a little picture that I have drawn of an Active Directory Domain. In that AD Domain are three different sites, one for Denver, one for Las Vegas, and one for Ft. Lauderdale.

If I have done my Active Directory site design appropriately, well then each site should correspond to one or more different ranges of IP Addresses or really Subnets. You see that the Denver site actually corresponds to the one net and the Las Vegas to the two net and the Ft Lauderdale site to the three net. Most people are used to thinking of Active Directory Science as a mechanism for logons and we position Active Directory Domain Controllers in each site so that users in that site can logon to a local Domain Controller.

What is interesting about sites is that each site, because of that mapping to that IP Address range, can also be used to help us determine the geolocation of that user. Now one of the things we can do with this geolocation information is use that in a login script to help us identify what kinds of printers, or which of the available local printers, we want to connect to that users machine whenever they log onto that site.

There are a couple of different things we need. First of all we are going to need some sort of mechanism for identifying what the site is. In my first little scriptlet over here I have actually created that. I am using VBScript here because a lot of us still use VBScript for our logon scripts. In this script I have an ADSystemInfo object that I am creating here. Ultimately I am referencing the SiteName method and if I double click it you will see that, yes, indeed I am in the Denver site.

So I have the site enumeration. The next thing I need to do is create some sort of conditional statement that helps me make a decision based off of what site that I am in. That is the second little scriptlet over here. You will see that once again I am creating an ADSystemInfo object I'm referencing SiteName. But depending on what sort of answer I get from that reference. I am going to do something different. In the case of Denver, I am going to pipe to the screen 'Go Denver!' In Las Vegas, 'Go Vegas!' For Lauderdale, 'Go Lauderdale!' I am just using this as an example to show you what the Select Case structure can be for helping you make decision about what printers you want to map.

If I double click this script, you will be able to see 'Go Denver!', because indeed I am in the Denver site. I need to then replace that WScript.Echo with a printer mapping. There are a couple of different ways that I can go about actually adding that printer mapping. The first is through the use of a WScript.Shell object. Now when I am using WScript.Shell what I am doing is effectively running an external executable inside of my VBScript. In this case I am running the rundll32.exe, executable. I am pointing it at the DLL, printui.dll and I am instructing this DLL to run the action PrintUIEntry. There are a series of switches out here in the back, but ultimately what I am doing is quietly installing the printer on the server
tricross with name \greg's.

Some of these DLLs actually have some information that I can pull up in the dialog box and to help me understand what this switch structure might be. I can actually go here to the Run prompt and open up a command prompt and ultimately just type in rundll32.exe, point it to printui.dll, and then execute the PrintUIEntrycommand with the /? switch to pull up the Printer User Interface dialog box. You will see in this dialog box I have all kinds of switches that I can do to configure the printer how I want to get connected, or disconnected, or whatever.

If I close this down, and close this down, this is one of the mechanisms I can use for attaching that printer. Admittedly, that is pretty heavyweight. Maybe I just want a lighter-weight approach. A lighter-weight approach involves some objects and some methods that are built right into VBScript. You will see here the WScript.Network object as an AddWindowsPrinterConnection method. That, very simply, connects to \\tricross\greg's.

If I run either of these, there really is not that much to see. Again I am trying to install these printers silently. Now having all these bits is great but I need to consolidate them ultimately down into a single script that takes everything and brings a full solution so that I can map users to the different printers in each site.'

Let me take a look at the final script that I have built. This script here has again another connection here to an ADSystemInfo object and I am doing another Wscript.Network as well but you will notice here in the middle I am doing an additional piece of verification that goes through all of the computers currently assigned to this computer and removes them before creating the new printer. This can be important so that I don't have any artifacts from the old site that are brought into the new site. Once I have gone through removing the printer connections then the last thing to do here is to identify what site I am in and ultimately add that window printer connection.