Retrieve remote computer info

Author Message
bluebird

  • Total Posts : 21
  • Scores: 1
  • Reward points : 0
  • Joined: 12/30/2006
  • Status: offline
Retrieve remote computer info Tuesday, February 20, 2007 2:52 AM (permalink)
0
Hi there,

I've made a script which retrieves on a remote computer some info. The list to of computers to be checked are listed in a textfile.
If you have any comments or suggestions I'd like to hear them.

 
 Option Explicit
 
 ' *******************************************************************************
 ' Author                 : Bluebird
 ' Title                     : ServerInfo.vbs
 ' Version                : 1.0
 ' Date                    : 19/02/2007
 ' 
 ' Description:
 ' This file uses the inputfile servers.txt with the different computers to check.
 ' This script will check each computer for the folowing information:
 ' - Available drives,  - Memory, - Which OU the computer is risided,
 ' - SQL version, - ISS version
 ' *******************************************************************************
 
 ' **** Declare constants **** 
 
 ' **** Constants for the textfile ****
 Const ForReading = 1, ForWriting = 2, ForAppending = 8
 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
 
 ' **** Constants for the OU information **** 
 Const ADS_NAME_INITTYPE_GC = 3
 Const ADS_NAME_TYPE_NT4 = 3
 Const ADS_NAME_TYPE_1779 = 1
 
 ' **** Declare global variables  **** 
 Dim objInputFile, strText, arrComputers, strComputer        ' Used for the input & output of the textfile
 Dim objFSO, wshNetwork, wshShell                            ' Some global stuff
 Dim objWMIService, SWBemlocator                                ' WMI connect to class stuff (Used for rive & memory info)
 Dim objService, objRegistry                                    ' WMI connect to register stuff (used for SQL & ISS)
 Dim UserName, Password                                        ' Credentials for login to WMI service
 Dim objItem, colItems                                        ' Needed for the loops
 
 ' **** User credentials ****
 UserName = ""
 Password = ""
 
 ' **** Declare standard sets **** 
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 Set wshShell = CreateObject("WScript.Shell")
 Set wshNetwork = CreateObject("WScript.Network")
 
 Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
 
 ' **** Select the inputfile ****
 If objFSO.FileExists("servers.txt") then
     Set objInputFile = objFSO.OpenTextFile("servers.txt", ForReading)
 Else 
     MsgBox ("File servers.txt not found!")
     WScript.Quit
 End if
 
 
 ' **** Read inputfile **** 
 strText = objInputFile.ReadAll
 objInputFile.Close
 ' Split the inputfile for computernames, which are seperated by a enterkey
 arrComputers = Split(strText, vbCrLf)
 
 
 ' **** Remove outputfiles if exist **** 
 For Each strComputer In arrComputers
     If objFSO.FileExists(strComputer & ".txt") Then
          objFSO.DeleteFile(strComputer & ".txt") 
     End If
 Next
 
 
 ' **** Create the textfile with server information **** 
 Function CreateTextFile(AppendText)
        Dim f, ts
     If Not (objFSO.FileExists(strComputer & ".txt")) Then
                  objFSO.CreateTextFile strComputer & ".txt"
                  Set f = objFSO.GetFile(strComputer & ".txt")
               Set ts = f.OpenAsTextStream(ForAppending, TristateUseDefault)
               ts.WriteLine "Document created on: " & date
                 ts.WriteLine ""
               ts.WriteLine "Server information for " & strComputer
               ts.WriteLine "---------------------------------------"
               ts.WriteLine ""
                ts.Close
     End If           
 
        Set f = objFSO.GetFile(strComputer & ".txt")
     Set ts = f.OpenAsTextStream(ForAppending, TristateUseDefault)
        ts.WriteLine AppendText
        ts.Close
 End Function
 
 
 ' **** Start reading the actions that need to be executed for each computer in the inputfile *****
 For Each strComputer In arrComputers
 
 '     -------------------------------------------------------------------------------
     ' **** Gather drive information **** 
     On Error Resume Next
     
     Set objWMIService = SWBemlocator.ConnectServer(strComputer,"root\CIMV2",UserName,Password)
     Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk",,48)
     
     For Each objItem in colItems
         If objItem.Description <> "CD-ROM Disc" Then
             CreateTextFile("Drive "& objItem.DeviceID & "\" & " Size: " & _ 
             Round( objItem.Size / 1073741824 ) ) & " GB"
         End If
     Next
     Set objWMIService = Nothing
     On Error Goto 0
     
     Set colItems = Nothing
     
 '     -------------------------------------------------------------------------------
     ' **** Gather memory information **** 
     Dim strComputerSystem_TotalPhysicalMemory, strTotalPhysicalMemoryMB
     
     Set objWMIService = SWBemlocator.ConnectServer(strComputer,"root\CIMV2",UserName,Password)
     Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
     
     For Each objItem In colItems
         strComputerSystem_TotalPhysicalMemory = objItem.TotalPhysicalMemory
         strTotalPhysicalMemoryMB = Round(strComputerSystem_TotalPhysicalMemory / 1024 / 1024)
             If strTotalPhysicalMemoryMB < 1024 Then
                 CreateTextFile("")
                 CreateTextFile("Memory: ") & strTotalPhysicalMemoryMB & " MB"
                 CreateTextFile("")
                 CreateTextFile("Type instance: Small")
             ElseIf strTotalPhysicalMemoryMB < 2048 Then
                 CreateTextFile("")
                 CreateTextFile("Memory: ") & strTotalPhysicalMemoryMB & " MB"
                 CreateTextFile("")
                 CreateTextFile("Type instance: Medium")
             ElseIf strTotalPhysicalMemoryMB < 8192 Then
                 CreateTextFile("")
                 CreateTextFile("Memory: ") & strTotalPhysicalMemoryMB & " MB"
                 CreateTextFile("")
                 CreateTextFile("Type instance: Complex")
             End If
     Next
     Set objWMIService = Nothing
     
 '     -------------------------------------------------------------------------------    
     ' **** Get OU information **** 
     On Error Resume Next    
     
     Dim objTrans, objDomain, GetDN
 
     Set objTrans = CreateObject("NameTranslate")
     Set objDomain = getObject("LDAP://rootDse")
     
     objTrans.Init ADS_NAME_INITTYPE_GC, ""
     objTrans.Set ADS_NAME_TYPE_NT4, wshNetwork.UserDomain & "\" _
     & strComputer & "$"
     GetDN = objTrans.Get(ADS_NAME_TYPE_1779)
     
     If IsNull(objTrans.Get(ADS_NAME_TYPE_1779)) Then
         CreateTextFile("")
         CreateTextFile("Computer is not found in a OU or you don't have enough rights to view")
     Else
         CreateTextFile("")
         CreateTextFile ("DN string is: "& objTrans.Get(ADS_NAME_TYPE_1779))
     End If
     
     On Error GoTo 0        
     
 '     -------------------------------------------------------------------------------
     ' **** Get SQL information **** 
     Dim strRegPath, strRegValue, strRegResult 
     
     Set objService = SWBemlocator.ConnectServer(strComputer, "Root\DEFAULT", _
                     UserName, Password)
     Set objRegistry = objService.Get("StdRegProv")
     
     strRegPath = "SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\CurrentVersion"
     strRegValue = "CurrentVersion"
     
     objRegistry.GetStringValue 2147483650, strRegPath, strRegValue, strRegResult
     If IsNull(strRegResult) Then
         CreateTextFile("")
         CreateTextFile("SQL server not found")
     Else 
         CreateTextFile("")
         CreateTextFile("SQL version " & strRegResult)
     End if
         
     Set objRegistry = Nothing
     Set strRegPath = Nothing
     Set strRegValue = nothing
 
 '     -------------------------------------------------------------------------------
     ' **** Get ISS information **** 
     Set objService = SWBemlocator.ConnectServer(strComputer, "Root\DEFAULT", _
                     UserName, Password)
     Set objRegistry = objService.Get("StdRegProv")
     
     strRegPath = "SOFTWARE\Microsoft\InetStp"
     strRegValue = "VersionString"
     
     objRegistry.GetStringValue 2147483650, strRegPath, strRegValue, strRegResult 
     If IsNull(strRegResult) Then
         CreateTextFile("")
         CreateTextFile("ISS not found")
     Else 
         CreateTextFile("")
         CreateTextFile("ISS " & strRegResult)
     End if
         
     Set objRegistry = Nothing
     Set strRegPath = Nothing
     Set strRegValue = nothing
 
 '     -------------------------------------------------------------------------------
 
 ' **** End reading the actions that need to be executed for each computer in the inputfile ****
 Next
 
 WScript.Echo ("Done!")
 
 
 
#1

    Online Bookmarks Sharing: Share/Bookmark

    Jump to:

    Current active users

    There are 0 members and 1 guests.

    Icon Legend and Permission

    • 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
    • Read Message
    • Post New Thread
    • Reply to message
    • Post New Poll
    • Submit Vote
    • Post reward post
    • Delete my own posts
    • Delete my own threads
    • Rate post

    2000-2012 ASPPlayground.NET Forum Version 3.9