Contents for Ezine 102 – Collect VBScript Methods
- This Week’s Secret
- This Week’s Mission
- Example: To Modify the Properties of Computer Objects
- Summary – Methods
This Week’s Secret is never miss a chance to collect a VBScript method. In the scripting model, objects such as user or computer are important, however, it’s the methods that convert plans into actions. Next week we will focus on the LDAP properties, for example, givenName, sAMAccountName and displayName, but this week it’s methods, such as .Put and .SetInfo that are caught in my spotlight.
I think of methods as the doers, the men of action. As I write my web pages, I search for the verb with just the correct shade of meaning, when I script I seek methods, which perform just the right action.
This Week’s Mission is to modify the computer object’s properties. I choose the computer because it’s often a neglected object, also I want to re-enforce the point that all Active Directory objects have more properties than you can imagine.
My hidden agenda is to alert you to the presence of two properties with similar names, description and displayName. As another aside, you can script information about the department to which your computers’ belong.
Import users from a spreadsheet. Just provide a list of the users with their fields in the top row, and save as .csv file. Then launch this FREE utility and match your fields with AD’s attributes, click and import the users.
Optionally, you can provide the name of the OU where the new accounts will be born. Download your FREE bulk import tool.
If you need more comprehensive software, download a free trial of SAM (Server & Application Monitor)
You need an OU called Accounts, else change my value for strContainer.
It makes sense to create or move two or three computer objects in the OU specified by the above strContainer.
This script is designed for Windows Active Directory. You really need to run this script on a domain controller rather than an XP workstation.
Instructions for modifying the properties of computer objects.
Copy and paste the example script below into notepad or use a VBScript editor.
One advantage of a good script editor such as OnScript is that you can see the line numbers, which helps when you have to troubleshoot error messages.
Save the file with a .vbs extension, for example: Description.vbs
Double click Description.vbs, the check Active Directory Users and Computers for new values for your computer’s properties.
N.B. It may be necessary to right-click the OU and select ‘Refresh’ from the drop down menu. F5 is only works the first time then goes silent.
‘ VBscript with methods to modify computer properties
‘ Author Guy Thomas https://computerperformance.co.uk/
‘ Version 1.2 – February 2006
Dim objRoot, objDomain, objOU, objComputer
Dim strContainer, intCounter
‘ Section to bind to ANY Active Directory.
Set objRoot = GetObject("LDAP://rootDSE")
objDomain = objRoot.Get("defaultNamingContext")
strContainer = strContainer & objDomain
set objOU =GetObject("LDAP://" & strContainer )
intCounter = 0
‘ Start of Loop.
‘ Note filter: If then…
For each objComputer in objOU
If objComputer.class="computer" Then
objComputer.Put "Description", "Laptop"
objComputer.Put "DisplayName", "Toshiba"
intCounter = intCounter +1
WScript.Echo intCounter & " Descriptions changed to Laptop"
Note 1: The first method, .Put is like typing (or pasting) the values into the computer’s property sheet; while the second method, .SetInfo is like pressing the OK button when you have finished modifying that object. Incidentally last week we employed the .Get and .Create methods.
Get into the rhythm of modifying object with methods. For example objComputer.Put, then the name of the property "Description", finally the value "Desktop".
Note 2: Following on from the previous ezine, this script binds to Active Directory then obtains the name of your domain, there is no need to hard-code dc=xyz. Nevertheless, do pay attention to strContainer, for instance this script requires a comma, after the name of the OU.
Note 3: Observe the simple but effective: For Each …. Next loop.
Note 4: This script uses the If … then … End If, to filter just computer objects.
SolarWinds’ Orion performance monitor will help you discover what’s happening on your network. This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.
What I like best is the way NPM suggests solutions to network problems. Its also has the ability to monitor the health of individual VMware virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.
1)My Active Directory challenge is to add more properties, for example:
objComputer.Put "Department", "Human Resources".
2)My scripting challenge is to introduce more variables, for example:
strDescription = "Acme Computers"
objComputer.Put "Description", strDescription
(in place of: objComputer.Put "Description", "Desktop")
Never miss the chance to learn a new VBScript method. Whenever you see a new script, by all means ‘parse’ it for the names of objects or properties, but in particular seek the methods. For example .Put and .SetInfo.