Monday, November 3, 2008

System Info OS and Service Pack Level

' **************************
' ServerInfo.vbs
' Collects OS and SP info
' List of systems must be in same directory as script
' Run using cscript
' **************************
' Name of Input File
strInputFile = "Syslist.txt"
' Name of Output File
strOutputFile = "ServerInfo.csv"

' Create file system object
set objFSO = CreateObject("Scripting.FileSystemObject")
' Check for Existing Output file, Create output file
If  objFSO.FileExists(strOutputFile) Then
   Wscript.echo "You must delete or remove " &  strOutputFile & " from this directory prior to running script"
   wscript.quit
End If
set objOutputFile = objFSO.OpenTextFile(strOutputFile, 2 , True)
If objFSO.FileExists(strInputFile) Then
  set objInStream = objFSO.OpenTextFile(strInputFile, 1)
' Begin reading input file
Set objWebmLocator = CreateObject("WbemScripting.SWbemLocator")
On Error Resume Next
Do While objInStream.AtEndOfStream <> True
 strComputer = objInStream.Readline
 'Wscript.echo ("Connecting to " & strComputer)
 Set objWMI = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" _
   & strComputer & "\root\cimv2")
 
 If Err.number <> 0 Then
  Err.clear
  Set objWMI = objWebmLocator.ConnectServer(strComputer, "root\CIMV2", strUser, strPassword)
 End If
 If Err.Number <> 0 Then
  objOutputFile.Writeline(strComputer & ",Unavailable")
  'WScript.echo ("Connection Failed")
 Else
  Set colOS = objWMI.ExecQuery("Select Caption From Win32_OperatingSystem")
  Set colSP = objWMI.ExecQuery("Select CSDVersion From Win32_OperatingSystem")
 
  intOSCount = 0
  intSPCount = 0
 
  For Each objOS In colOS
   intOSCount = intOSCount + 1
   strOSVal = Replace(objOS.Caption, ",", " ")
  Next
  For Each objSP in colSP
   intSPCount = intSPCount + 1
   strSPVal = objSP.CSDVersion
  Next
  If intOSCount + intSpCOunt > 2 Then
   strVerified = "Unconfirmed"
  Else
   strVerified = "Confirmed"
  End If
  objOutputFile.Writeline(strComputer & "," & strOSVal & "," & strSPVal & "," & strVerified)

 End If
 Err.Clear
 
Loop
End IF
wscript.echo ("Script Complete")
wscript.quit

-------------------
Thanks,
http://paddymaddy.blogspot.com/

No comments: