Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dumping All Computer information Problem 1

Status
Not open for further replies.
Sep 29, 2002
524
US

I am trying to write a script that dumps computer information to a file. Right now, I have the script setup to write to the screen in order to troubleshoot easier. The following code seems to work fine for the first server but then it errors out and says:

test.vbs(13, 5) Microsoft VBScript runtime error: The remote server machine does not exist or is unavailable: 'GetObject'


Code:
Dim arrServers(3)

arrServers(0) = "Server1"
arrServers(1) = "Server2"
arrServers(2) = "Server3"
arrServers(3) = "Server4"

For cServers = 0 To 3
  strComputer = arrServers(cServers)
  strPingStatus = PingStatus(strComputer)
  If strPingStatus = "Success" Then

    set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    set colAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
  
    For Each objAdapter in colAdapters

      Wscript.StdOut.Write objAdapter.DNSHostName & ", "
 
      If Not IsNull(objAdapter.IPAddress) Then
        For i = 0 To UBound(objAdapter.IPAddress)
           Wscript.StdOut.Write objAdapter.IPAddress(i) & ", "
        Next
      End If
 
      If Not IsNull(objAdapter.IPSubnet) Then
        For i = 0 To UBound(objAdapter.IPSubnet)
           Wscript.StdOut.WriteLine objAdapter.IPSubnet(i)
        Next
      End If
    NEXT
  ELSE
    Wscript.StdOut.Writeline strComputer
  End If
  
NEXT

'******************************************************************************

Function PingStatus(strComputer)

    On Error Resume Next
    strWorkstation = "."
    Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" & strWorkstation & "\root\cimv2")
    Set colPings = objWMIService.ExecQuery _
      ("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComputer & "'")
    For Each objPing in colPings
        Select Case objPing.StatusCode
            Case 0 PingStatus = "Success"
            Case 11001 PingStatus = "Status code 11001 - Buffer Too Small"
            Case 11002 PingStatus = "Status code 11002 - Destination Net Unreachable"
            Case 11003 PingStatus = "Status code 11003 - Destination Host Unreachable"
            Case 11004 PingStatus = _
              "Status code 11004 - Destination Protocol Unreachable"
            Case 11005 PingStatus = "Status code 11005 - Destination Port Unreachable"
            Case 11006 PingStatus = "Status code 11006 - No Resources"
            Case 11007 PingStatus = "Status code 11007 - Bad Option"
            Case 11008 PingStatus = "Status code 11008 - Hardware Error"
            Case 11009 PingStatus = "Status code 11009 - Packet Too Big"
            Case 11010 PingStatus = "Status code 11010 - Request Timed Out"
            Case 11011 PingStatus = "Status code 11011 - Bad Request"
            Case 11012 PingStatus = "Status code 11012 - Bad Route"
            Case 11013 PingStatus = "Status code 11013 - TimeToLive Expired Transit"
            Case 11014 PingStatus = _
              "Status code 11014 - TimeToLive Expired Reassembly"
            Case 11015 PingStatus = "Status code 11015 - Parameter Problem"
            Case 11016 PingStatus = "Status code 11016 - Source Quench"
            Case 11017 PingStatus = "Status code 11017 - Option Too Big"
            Case 11018 PingStatus = "Status code 11018 - Bad Destination"
            Case 11032 PingStatus = "Status code 11032 - Negotiating IPSEC"
            Case 11050 PingStatus = "Status code 11050 - General Failure"
            Case Else PingStatus = "Status code " & objPing.StatusCode & _
               " - Unable to determine cause of failure."
        End Select
    Next

End Function

Any ideas? :-(


Gladys Rodriguez
GlobalStrata Solutions
Computer Repair, Website Design and Computer Consultant
Small Business Resources
 
perhaps in your PingStatus function you need to initialise the return string??? say set a default,

Function PingStatus
strTemp = "Failed"
''''.....

Case 0 strTemp = "Success"

PingStatus = strTemp
End Function

'or perhaps in your script body you need to do something like
For cServers = 0 To 3
strComputer = arrServers(cServers)
strPingStatus = ""
strPingStatus = PingStatus(strComputer)
If strPingStatus = "Success" Then


 
Hi, I suspect that Server2 has a problem with wmi. You can catch the error like this:
Code:
If strPingStatus = "Success" Then
on error resume next
    set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
If Err.Number <> 0 Then
     Wscript.StdOut.Write "wmi error: " & err.number
     err.clear
else
     set colAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
  
    For Each objAdapter in colAdapters
   "your code "
end if

Hope I could be of assistance
Regards
Thomas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top