myITforum.com Community Forum myITforum.com Community Forum

Home  Forums  Blogs  Live Support chat  Search Articles  Wiki  FAQ  Email Lists  Register  Login  My Profile  Inbox  Address Book  My Subscription  My Forums 

Photo Gallery  Member List  Search  Calendars  FAQ  Ticket List  Log Out

All Forums RSS Feed Subscription:


  


OS and Service pack Script

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
  Printable Version
All Forums >> [Scripting Technologies] >> VB Script >> OS and Service pack Script Page: [1]
Login
Message << Older Topic   Newer Topic >>
OS and Service pack Script - 10/3/2008 3:42:07 PM   
jschramke


Posts: 64
Score: 4
Joined: 9/5/2002
From: Princeton, New Jersey
Status: offline
Here is a script I wrote to collect operating system and service pack from a list of remote systems.  This must be run using cscript in a shell window.  Place a text file named syslist.txt in the same directory as the script.  This file must contain the computer names of all of the hosts (workstations and/or servers) with one name per line and no extra spaces.  The output will be displayed in the shell window and written to a comma-separated text file named ServerInfo.csv (can be opened in MS Excel).  If a system is inaccessible, this will be noted in the output file.  Any existing ServerInfo.csv files in the directory must be deleted before running the script.  Any system with an unconfirmed notation should be manually verified

You will be prompted for local account credentials for the server.  The script will first attempt to authenticate using the current users AD credentials and then the local credentials if authentication fails.

Copy and paste the code below into a file anmed ServerInfo.vbs or use the attached file and change the extension to vbs.

Open a shell window, change the directory to the location of the script file and system list and enter "cscript ServerInfo.vbs" (w/o quotes).

' **************************
' ServerInfo.vbs
' Copyright Jason Schramke
' 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"
' Prompt for local account username/pw
wscript.echo "Please enter the local administrator account name:"
strUser = Wscript.StdIn.ReadLine
Set objPassword = CreateObject("ScriptPW.Password")
wscript.echo "Password:"
strPassword = objPassword.GetPassword()

' 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


Author does not guarantee the accuracy of the information generated by this code.  Use at your own risk.  Not for sale or redistribution.


Attachment (1)

_____________________________

| Jay Schramke |
Post #: 1
Page:   [1]
All Forums >> [Scripting Technologies] >> VB Script >> OS and Service pack Script Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts



  
Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.250