Hi there, I need a vbscript which will query active directory for computers and output the following criteria:
Name | Operating System | Service Pack | Distinguished Name | Enabled or Disabled? | Last Logon Date / Time
I have found the following script which gets me some of the required info but I cant get it to find the enabled / disabled or last logon bit, can anyone help? Here is what I have so far:
Const ADS_SCOPE_SUBTREE = 2
strDomain = "LDAP://DC=CONTOSO,DC=COM"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = "Select name,aDSPath,operatingSystem,operatingSystemServicePack,distinguishedName from '" & strDomain & "' Where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
If oFSO.FileExists("c:\users\john\documents\temp\computer_list.csv") Then oFSO.DeleteFile("c:\users\john\documents\temp\computer_list.csv")
Set oFile = oFSO.OpenTextFile("c:\users\john\documents\temp\computer_list.csv",2,True)
On Error Resume Next
Do Until objRecordSet.EOF
data = ""
data = data & objRecordSet.Fields("name").Value & ","
data = data & objRecordSet.Fields("operatingSystem").Value & ","
data = data & objRecordSet.Fields("operatingSystemServicePack").Value & ","
data = data & Left(objRecordSet.Fields("distinguishedName").Value, InStr(objRecordSet.Fields("distinguishedName").Value,",")-1) & ","
Set oComputer = GetObject(objRecordSet.Fields("aDSPath").Value)
data = data & oComputer.Get("description") & ","
oFile.WriteLine data
objRecordSet.MoveNext
Loop
On Error GoTo 0
oFile.Close
WScript.Echo("Finished")
Thanks in advance
- Edited by jonnyp1381 12 hours 56 minutes ago