The below script will create a CSV file listing the Name, Description, Operating System and Service Pack level of all computers in an Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE") strDNSDomain = objRootDSE.Get("defaultNamingContext") set objConn = CreateObject("ADODB.Connection") set objCmd = CreateObject("ADODB.Command") objConn.Provider = "ADsDSOObject" objConn.Open "Active Directory Provider" Set objCmd.ActiveConnection = objConn objCmd.Properties("Cache Results") = False strFilter = "(&(objectclass=computer)(objectcategory=computer))" strQuery = "<LDAP://" & strDNSDomain & ">;" & strFilter & ";distinguishedName;subtree" objCmd.CommandText = strQuery Set wshFSO=Createobject("Scripting.FileSystemObject") Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8 strCSVPath = "C:\Computer_Details.csv" if wshFSO.FileExists(strCSVPath) then wshFSO.deletefile(strCSVPath) end if Set objLogFile = wshFSO.CreateTextFile(strCSVPath) objLogFile.Write("CN, Description, OS, SP" & chr(13) & chr(10)) Set objRecordSet = objCmd.Execute Do Until objRecordSet.EOF strDN = objRecordSet.Fields("distinguishedName") Set objComputer = GetObject("LDAP://" & strDN) strCN = objComputer.cn strDesc = objComputer.description strOS = objComputer.operatingSystem strSP = objComputer.operatingSystemServicePack objLogFile.Write(strCN & ", " & strDesc & ", " & strOS & ", " & strSP & chr(13) & chr(10)) objRecordSet.MoveNext Loop msgbox "Complete." & vbLF & "Ouput has been saved to " & strCSVPath objLogFile.close objConn.Close Set objGroup = Nothing Set objRootDSE = Nothing Set objCmd = Nothing Set objConn = Nothing
The above command is working fine. Good preparation. Keep it up 🙂
Cheers
Srinivas
This script kills over after 1000 computers, how do I extend that?