Script Active directory to get computer name and Operating System type

I need to get a list of all the servers we have on lan and the operating system that they have installed
Can I run a script against AD to get this information

Does anyone have any good way to get this info
neoptoentAsked:
Who is Participating?
 
Henrik JohanssonConnect With a Mentor Systems engineerCommented:
Use CSVDE to get a CSV-file with the result.
C:\>csvde -f output.csv -d dc=domain,dc=com -r "(objectClass=computer)" -l name,operatingsystem
0
 
tigermattCommented:
How many servers do you have? If it's only a few, you could just look at the properties of the objects of these servers in Active Directory. It will tell you OS and Service Pack information in there, which means you don't need a script.
0
 
neoptoentAuthor Commented:
There are a few hundred machines

I cant do it manually
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
coolsport00Commented:
Yes..via VBScript. It places the info in an excel .csv file on the root of C:\. You can then modify it as needed. Just copy and paste the following in notepad, put your org name in where I have CAPS, save it as .vbs file and run it:
_________________________________________________________________________________________
Const ADS_SCOPE_SUBTREE = 2
Const LOGFILE = "C:\OSverScript.csv"  ' Log file path and name

' ** Create the database connection, command, and recordset objects

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
Set objRecordset = CreateObject("ADODB.Recordset")

' ** Create and open the text file

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(LOGFILE,True)

' ** Set the provider and open Active Directory

objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

' ** Set the properties of the command object to select the OS and Version

Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
                "SELECT Name, operatingSystem, operatingSystemVersion " _
                & "FROM 'LDAP://DC=YOURDOMAIN,DC=COM' " _
                & "WHERE objectClass='computer' " _
        & "ORDER BY operatingSystem"  
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

' ** Execute the command to get the Active Directory info
' ** Place the data in the recordset

Set objRecordset = objCommand.Execute

' ** Write the values of the recordset to the text file

objRecordset.MoveFirst      ' Point to first record
Do Until objRecordset.EOF
      strLine = ""
      
      ' ** Add the computer name to the output line
      strValue = ""
      If Not IsNull(objRecordset.Fields("Name").Value) Then _
            strValue = CStr(objRecordset.Fields("Name").Value)
      strLine = strLine & strValue & ","

      ' ** Add the Operation system to the output line
      strValue = ""
      If Not IsNull(objRecordset.Fields("operatingSystem").Value) Then _
            strValue = CStr(objRecordset.Fields("operatingSystem").Value)
      strLine = strLine & strValue & ","
      
      ' ** Add the Operation system version to the output line
      strValue = ""
      If Not IsNull(objRecordset.Fields("operatingSystemVersion").Value) Then _
            StrValue = CStr(objRecordset.Fields("operatingSystemVersion").Value)
      strLine = strLine & strValue
      
      ' ** Write the line to the text file
      objFile.WriteLine(strLine)
  objRecordset.MoveNext            ' next record
Loop

' ** Close the text file, recordset and connection, and release all the objects

objFile.Close
objRecordset.Close
objConnection.Close
Set objFile = Nothing
Set objFSO = Nothing
Set objRecordset = Nothing
Set objConnection = Nothing
Set objCommand = Nothing
Set objRecordset = Nothing
__________________________________________________________________________________________


I know it looks overwhelming, but you don't have to do anything but change your domain name above.

Hope that helps.

Regards,
~coolsport00
0
 
neoptoentAuthor Commented:
Hi,

when I do this I get error line 24 character 1 table does not exist
0
 
neoptoentAuthor Commented:
Line 34 sorry
0
 
coolsport00Commented:
I re-ran the code here and it worked with no errors. VB, like any coding is VERY picky. :)  Make sure you look at the code I pasted and that you pasted it with all the "ticks" ('), quotes, and spaces. The ticks are used in front of lines for commenting (i.e. it's not actual VB code that runs). I assume you changed the LDAP part above? ("FROM 'LDAP://DC=YOURDOMAIN,DC=COM' " _)
0
 
neoptoentAuthor Commented:
I tried to recopy it and still got th error .

Can you try to put it in again as "attach code snippet"

Maybe that will make a diff?
0
 
coolsport00Commented:
Here you go...try this. :)
GetOSVer.txt
0
 
neoptoentAuthor Commented:
Do I need to run this on the dc?

Zach
0
 
coolsport00Commented:
I have the Win2K3 Admin Tools (and thus AD U&C) on my laptop so I run it from here and it works. I didn't try running it on a regular desktop. I had one of my developers write that for me as I'm not a huge VB scriptor...can only make out what the script is doing. I write smaller, easier scripts. :)

Try running it on a DC or at least on a PC that has the admin tools on it and see if it works. I assume you're still getting the error?
0
 
neoptoentAuthor Commented:
The error has moved to line 41 now
0
 
neoptoentAuthor Commented:
The CSVDE has worked. Thanks for all with the help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.