On Error Resume Next
Dim domain 'As IADsDomain, IADsContainer, IADs
Dim computer 'As IADsComputer, IADs, strResults
Set domain = GetObject("WinNT://<Your workgroup or domain name goes here>")
domain.Filter = Array("Computer")
For Each computer In domain
strComputer = computer.Name
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("SELECT * FROM Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
strResults = "Computer Name: " & strComputer & vbCR
strResults = strResults & "OS Version: " & objOperatingSystem.Version & vbCR
strResults = strResults & "Build number: " & objOperatingSystem.BuildNumber
MsgBox strResults
Next
Next
MsgBox "Finished"
The above, copied and pasted into a Notepad file, and saved with a VBS extenstion will enumerate all connected and active computers, and display their name, version and build number. Replace the <Your workgroup or domain name goes here> with the actual work group or domain name. For computers to respond, they must have WMI installed and enabled. Just double click the VBS file to run it.
To write the results to a text file, instead of the Message Box format, download the VB Script documentation and familiarize yourself with the FileSystemObject.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/scriptinga.asp