Computer Name Targeting
Obtain a dynamic list of computers for remote action targeting.
I see lots of people who write scripts to run against a text file that contains a list of target computers. There are lots of ways to get a list of computer names into that text file. There are lots of ways to get a list of computer names from your network. So why not collect computer names right within the same script? Here is something to get you started:
Set oCn = CreateObject("ADODB.Connection")
Set oCmd = CreateObject("ADODB.Command")
oCn.Provider = "ADsDSOObject"
oCn.Open "Active Directory Provider", "appdeploy\admin", "mypassword"
Set oCmd.ActiveConnection = oCn
oCmd.CommandText = "SELECT name FROM 'LDAP://appdeploy.local' WHERE objectCategory='computer'"
Set oRS = oCmd.Execute
Do Until oRS.EOF
This code will echo a list of computers to a simple text file named "computers." In the Do loop you could just as easily perform the action for which you might normally use the computer list. That's really the idea -- why have more files to work with than necessary?
The fourth line where the connection is opened, you can normally have just oCn.Open "Active Directory Provider". The second two arguments are optional and may be used if you will not be running the script with an account that has permissions to the domain you wish to query. The arguments are the domain and User ID and the last is the password (enclosed in double quotes).
Tech Help—Just An
Got a Windows, Exchange or virtualization question
or need troubleshooting help? Or maybe you want a better
explanation than provided in the manuals? Describe
your dilemma in an e-mail to the MCPmag.com editors
at [email protected];
the best questions get answered in this column and garner
the questioner with a nifty Redmond T-shirt.
When you send your questions, please include your
full first and last name, location, certifications (if
any) with your message. (If you prefer to remain anonymous,
specify this in your message, but submit the requested
information for verification purposes.)
The Select statement should look familiar to anyone that has worked with databases. Active Directory is in fact a directory, so in this case we are looking for the name field for all systems in LDAP://appdeploy.local (my domain) where the objectCategory is computer.
Now, where I currently have the Wscript.Echo command to display the name, you may take whatever code you might normally apply to a remote machine and place it here.
Bob Kelly is president and co-founder of AdminScriptEditor.com, home to an integrated suite of scripting tools and a shared library of scripts and language help. He has authored books on scripting and desktop administration and several white papers. Bob also owns and operates AppDeploy.com, where he writes and produces videos on topics related to software deployment.