'QueryDescription.vbs 'Outputs a list of computers whose description 'prefix matches the strPrefix variable 'set variables 'strPrefix -- physical or virtual identifier prefix ' to search for ' Prefix values: ' Ps – Physical server ' Vesx – VMware ESX VM ' Vms – Microsoft Virtual Server VM ' Vxen – Xen VM ' Vvi – Virtual Iron VM ' Vvz – SWsoft Virtuozzo virtual private server ' Vscon – Solaris Container ' V - Virtual (all VMs) strPrefix = "V" 'strDomainTarget -- this is the AD container ' where the target computer accounts are located strDomainTarget = "dc=virtual,dc=net" 'strLogFile -- output log file strLogFile = "c:\computers-" & strPrefix & ".txt" ' Constants Const ForWriting = 2 'Open Output Log File Set objFSO = CreateObject("Scripting.FileSystemObject") set objLogFile = objFSO.OpenTextFile(strLogFile,_ ForWriting, True) 'Connect to Directory Service, query for computer 'objects that have the desired Description 'attribute prefix, and output computer list to 'text file. set objConn = createObject("ADODB.Connection") set objCommand = createObject("ADODB.Command") objConn.Provider = "ADsDSOObject" objConn.Open "Active Directory Provider" Set objCommand.ActiveConnection = objConn 'Modify query based on value of strPrefix variable strprefix = lcase(strprefix) Select Case strPrefix Case "ps" objCommand.CommandText = "Select Name," &_ "Description FROM 'LDAP://" &_ strDomainTarget & "'" & " WHERE " &_ "objectCategory = 'computer' AND" &_ " description = 'Ps*'" Case "vesx" objCommand.CommandText = "Select Name," &_ "Description FROM 'LDAP://" &_ strDomainTarget & "'" & " WHERE " &_ "objectCategory = 'computer' AND" &_ " description = 'Vesx*'" Case "vms" objCommand.CommandText = "Select Name," &_ "Description FROM 'LDAP://" &_ strDomainTarget & "'" & " WHERE " &_ "objectCategory = 'computer' AND" &_ " description = 'Vms*'" Case "vxen" objCommand.CommandText = "Select Name," &_ "Description FROM 'LDAP://" &_ strDomainTarget & "'" & " WHERE " &_ "objectCategory = 'computer' AND" &_ " description = 'Vxen*'" Case "vvi" objCommand.CommandText = "Select Name," &_ "Description FROM 'LDAP://" &_ strDomainTarget & "'" & " WHERE " &_ "objectCategory = 'computer' AND" &_ " description = 'Vvi*'" Case "vvz" objCommand.CommandText = "Select Name," &_ "Description FROM 'LDAP://" &_ strDomainTarget & "'" & " WHERE " &_ "objectCategory = 'computer' AND" &_ " description = 'Vvz*'" Case "vscon" objCommand.CommandText = "Select Name," &_ "Description FROM 'LDAP://" &_ strDomainTarget & "'" & " WHERE " &_ "objectCategory = 'computer' AND" &_ " description = 'vscon*'" Case "v" objCommand.CommandText = "Select Name," &_ "Description FROM 'LDAP://" &_ strDomainTarget & "'" & " WHERE " &_ "objectClass = 'computer' AND" &_ " description = 'V*'" End Select objCommand.Properties("Page Size") = 1000 objCommand.Properties("Timeout") = 30 objCommand.Properties("Cache Results") = False Set objComputerRecords = objCommand.Execute ' Write Output Log File Header objLogFile.writeline("The following computers " &_ "have the " & strPrefix & " Description Prefix:") objLogFile.writeline() objLogFile.writeline("Computer Name") objLogFile.writeline("=============") ' Output computer list to text file Do Until objComputerRecords.EOF strName = objComputerRecords.Fields("name").Value strDesc = objComputerRecords.Fields("description").Value objLogFile.writeline(strName) objComputerRecords.MoveNext Loop wscript.echo("Query complete! " &_ "Please open the " & strLogFile & " file " &_ "to view the results.")