Link to home
Start Free TrialLog in
Avatar of waltforbes
waltforbesFlag for Bahamas

asked on

Windows OS Version: How to remotely query for it?

Points of My Scenario:
1. I am Windows admin for a Server 2003 domain.
2. Windows OS versions include XP, 2003 (Standard & Enterprise), and 2008 R2.
QUESTION:
What command can I use from my workstation to query servers for the OS version and Editions?
Avatar of theraff
theraff

There's probably a better (read: Windows-specific) answer to this question, but I'd use nmap. This is available in most Linux distros, but you can get a Windows compatible version here.
SOLUTION
Avatar of Don
Don
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Save this as GetOS.vbs or Whatever.vbs; you can run it using cscript or wscript, and either pass the computer to query in the command line ("GetOS.vbs /computer:SomeMachine"), or it will prompt you for a name:
Function Get_Host()
	If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then
		Get_Host = "GUI"
	Else
		Get_Host = "CLI"
	End If
End Function

Function Get_Input(strHost, strPrompt)
	If (strHost = "GUI") Then
		Get_Input = InputBox(strPrompt)
	Else
		WScript.StdOut.Write strPrompt
		Get_Input = WScript.StdIn.ReadLine
	End If
End Function

Function Write_Output(strHost, strLine)
	If (strHost = "GUI") Then
		MsgBox(strLine)
	Else
		WScript.StdOut.Write strLine & vbCRLF
	End If
End Function

Function Get_OS(strComputer)
	Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	Set colOS = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
	For Each objOS in colOS
		Get_OS = objOS.Caption & " " & objOS.Version
	Next
End Function

'MAIN
strHost = Get_Host
Set objArgsNamed = WScript.Arguments.Named
strComputer = objArgsNamed("Computer")
If (strComputer = "") Then
	strComputer = Get_Input(strHost, "Please enter the computer name: ")
End If
If (strComputer = "") Then
	strComputer = "."
End if
strOSVersion = Get_OS(strComputer)
Write_Output strHost, strComputer & ": " & strOSVersion

Open in new window

Avatar of waltforbes

ASKER

To oBdA: your script and switch is 99% perfect! I love it! The 1% outstanding: How can I direct output to a text file? I tried "GetOS.vbs /computer:SomeMachine > textfile.txt", but it created a zero-byte file and still sent the output to screen.

To dstewartjr: your excellent script provides more info than oBdA; however, how can I provide computer names from a file and redirect output to an output file? I want to do the following or similar - "yourscript.bat /sourcefile:servernames.txt > results-output.txt"
To send the output to a file, you'll need to use cscript as host; the message box output of the wscript version can't be redirected:
cscript.exe GetOS.vbs /computer:SomeMachine > textfile.txt
Sorry, not my script....probably would need to modify for sure.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To oBdA:
1. I created a "servers.txt" file containing the server names - one per line.
2. I created the script "GetOS-InputFile.vbs" containing the contents of your 2nd script.
3. At the command prompt I changed to the directory containing both vbs & txt files.
4. I typed: "cscript.exe GetOS-InputFile.vbs /ComputerFile:servers.txt /ResultFile:results.log"
...and
...IT WORKED!!
You saved the day! Thank you!
1. oBdA provided me the perfect solution.
2. dstewartjr provided me a good solution for dealing with a few machines at a time.
I am well satisfied.