'QueryVirtualAttributes.vbs 'Outputs a list of computers whose isVirtual 'attribute is set to true. The output file also 'lists the vmType attribute value for each computer. 'set variables 'strVMtype -- Virtualization platform identifier 'set strVMtype to a specific identifier value or ' to "V" to list all VMs ' strVMtype values: ' 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) strVMtype = "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-" & strVMtype & ".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 isVirtual attribute 'set to true. Output computers whose vmType 'attribute matches the strVMtype variable 'to a text file. set objConn = createObject("ADODB.Connection") set objCommand = createObject("ADODB.Command") objConn.Provider = "ADsDSOObject" objConn.Open "Active Directory Provider" Set objCommand.ActiveConnection = objConn objCommand.CommandText = "Select Name," &_ "isVirtual, vmType FROM 'LDAP://" &_ strDomainTarget & "'" & " WHERE " &_ "objectClass = 'computer'" 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 " & strVMtype & " vmType attribute") objLogFile.writeline() objLogFile.writeline("Name" & vbtab & "VM Type") objLogFile.writeline("====" & vbtab & "=======") ' Output computer list to text file Do Until objComputerRecords.EOF strName = objComputerRecords.Fields("name").Value strType = objComputerRecords.Fields("vmType").Value If objcomputerRecords.Fields("isVirtual").value = true Then If strVMtype = "V" Then objLogFile.writeline(strName & vbtab & strType) ElseIf lcase(strType) = lcase(strVMtype) Then objLogFile.writeline(strName & vbtab & strType) End If End If objComputerRecords.MoveNext Loop wscript.echo("Query complete! " &_ "Please open the " & strLogFile & " file " &_ "to view the results.")