Real World Computing
Code in the head
Called the ADSI Scriptomatic, it's a ten-second download followed by the extraction of two files, one of which is an explanatory document written in the Scripting Guys' own inimitable style. You might not like the style, but this is free so stick with it. Get it via www.pcpro.co.uk/links/164sr.
The code generated by Scriptomatic looks more complex, but as you don't actually have to do anything more than supply the names of the objects you want to create, delete, write to, or read from, your job isn't going to be too complex. Here's the code generated by Scriptomatic to create an Organisational Unit called ImaTestOU, immediately below the root of a domain. All I had to do was supply the name of the OU, which I did in line two:
strContainer = ""
strName = "ImaTestOU"
If strContainer = "" Then
Set objContainer = GetObject("LDAP://" & _
ObjRoot'
***********************************************
'* Connect to a container *
'***********************************************
Set objRootDSE = GetObject("LDAP://rootDSE")
DSE.Get("defaultNamingContext"))
Else
Set objContainer = GetObject("LDAP://" & strContainer & "," & _
objRootDSE.Get("defaultNamingContext"))
End If
'***********************************************
'* End connect to a container *
'***********************************************
Set objOrganizationalunit = objContainer.Create("organizationalUnit", "ou=" & strName)
objOrganizationalunit.SetInfo
Once I'd got through the laborious task of typing ImaTestOU, I was then forced to click on the Run button before anything would happen. You'd think the Scripting Guys would have been clever enough to know what I wanted to have happen, but, hey, we can't have it all.
I could just have invented the next great game, however. Rewrite the Scriptomatic (being an HTML application, it's entirely scriptable) to run off a timer. Have different levels of timer. People get a fixed amount of time to make their script changes before the Run command executes, and you vary the time based on your belief in your abilities.
Regardless of whether you decide to roll your own, or use a Scriptomatic to help you, scripting is the way forward if you need to do a lot of the same thing. You could easily create a new account in the time it takes to write a script to do it for you, but you couldn't do ten in the same time it takes to do one, and you certainly couldn't do 20, 30, several hundred or several thousand in one shot unless you use a script.
The code I wrote earlier to create a user does just that. It creates the account, but doesn't do anything useful like adding names or descriptions. If you want to do that, you just add a few more lines to the code. Here's a selection of items you can add while creating a user account:
objUser.Put "givenName", "Ima"
objUser.Put "initials", "I.T."
objUser.Put "sn", "Test"
objUser.Put "displayName", "Ima Test"
objUser.Put "description", "A test account"
objUser.Put "physicalDeliveryOfficeName", "Room 101"
Other attributes you can set directly include:
telephoneNumber, otherTelephone, mail, wWWHomePage, url
Aside from AD, there are, of course, other areas that benefit from scripting. The Windows Management Interface (WMI) springs to mind immediately, and that's always been a notoriously hard area to script - or it was until the Microsoft Scripting Guys brought out Scriptomatic 2, which is designed to do for WMI what the ADSi Scriptomatic does for ADSI scripting.
