VBScript to list the OS Version of all computers in domain
In a large environment, inventory information can quickly be out of date. Below is a script that searches AD for all computers and then reports the OS from each system. The OS information comes from the target computer, so firewalls and power state is important.
'OSVersion.vbs
on error resume next
Const ADS_SCOPE_SUBTREE = 2
strDomain = "mydomain.com"
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, Location from 'LDAP://" & strDomain & "' Where objectCategory='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
QueryServer objRecordSet.Fields("Name").Value
objRecordSet.MoveNext
Loop
SUB QueryServer(strServer)
on error resume next
Set objWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate,(Security)}!\" & strServer & "rootcimv2")
SET objOSs = objWMI.ExecQuery("select * from Win32_OperatingSystem")
For Each objOS in ObjOSs
strCaption = objOS.Caption
strBuildNumber = objOS.BuildNumber
wscript.echo strServer & "," & strCaption' & " - " & strBuildNumber
NEXT
END SUB
how can you export the out put to a file? thank you.