Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

About the WMI Select command 2

Status
Not open for further replies.

JPJeffery

Technical User
May 26, 2006
600
GB
I have a script (lifted straight off a Hey! Scripting Guy! page) which includes the following line:
Code:
"SELECT ADsPath FROM 'LDAP://dc=ourdomainname,dc=com' WHERE objectCategory='computer'"

All I've changed is the word 'user' to 'computer' (the original code snippet was to pull out user account created date and last password set date, I just want the created date for the computer account).

What I need to do is further specify the WHERE command to only query the details for the current computer name but what I've not been able to find is a source that lists the WHERE command syntax.

I could do some kind of IF statement to ignore anything returned for a computer name OTHER than the current one, I know, but that seems awfully clumsy. It would be far more elegant to create code that only queries the one account (rather than all the accounts).

So, does anyone have a URL that shows the SELECT command syntax, please? I'm damned if I can't find one...even this one doesn't tell me very much:

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
AND sAMAccountName='" & strConputername & "$'")
 
the select syntax is straight out of SQL syntax, have a look for SQL sites :)
 
sorry WMI uses WQL slightly different from SQL syntax

could you use

Set objADSInfo = CreateObject("adsysteminfo")
Wscript.Echo objADSInfo.ComputerName
Set objComputer = GetObject("LDAP://" & objADSInfo.ComputerName)
 
Code:
[green]'Get the computer name[/green]
Set WSHNetwork = CreateObject("Wscript.Network")
strComputer = WSHNetwork.ComputerName

[green]'bind to rootDSE so we can get the domain info[/green]
Set oRootDSE = GetObject("LDAP://rootDSE")

[green]'connect to AD and do our query[/green]
Set oConnection = CreateObject("ADODB.Connection")
oConnection.Open "Provider=ADsDSOObject;"
Set oCommand = CreateObject("ADODB.Command")
oCommand.ActiveConnection = oConnection
oCommand.CommandText = "<LDAP://" & oRootDSE.get("defaultNamingContext") & _
    ">;(&(objectCategory=computer)(samAccountName=" & strComputer & "$));createTimeStamp;subtree"
Set oRecordSet = oCommand.Execute
[green]'show the results[/green]
WScript.echo oRecordSet.Fields("createTimeStamp")

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thanks, guys.

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top