Home All Groups Group Topic Archive Search About


Author
2 Apr 2007 7:24 AM
George
Hi ,

I am running a script to find the last restart time for a group of servers.
This script reads the server names from a text file and connect to that
server and returns the last restart time. This info will be written to a
file. Attached at the end of this.

But some of the servers will be not reachable/accessable. I want the
indication that those servers are not reachable.

For example Output should like this:

IP address   Last restart time
10.10.10.1   20070331115922.500000-240
10.10.10.2   Not reachable

I like to take the output to an excel file . Restart time should be in the
second cell.

Current running script:
---------------------------
On error resume Next
Const ForReading = 1
Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("C:\servers.txt", ForReading)

Set objTextFile1 = objFSO.OpenTextFile _
    ("C:\last_reboot.csv", ForAppending, True)

Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    arrServiceList = Split(strNextLine , ",")


strComputer = arrServiceList(0)

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


Set colOS = objWMIService.ExecQuery _
("SELECT * FROM Win32_OperatingSystem")

For Each objOS in colOS
objTextFile1.Writeline arrServiceList(0) & vbtab & objOS.LastBootUpTime & vtab
Next

Loop


----------------------

Can you please help me out.

Regards,
George

Author
2 Apr 2007 8:49 AM
Marcus Schmitt
George schrieb:
Show quote
> Hi ,
>
> I am running a script to find the last restart time for a group of servers.
> This script reads the server names from a text file and connect to that
> server and returns the last restart time. This info will be written to a
> file. Attached at the end of this.
>
> But some of the servers will be not reachable/accessable. I want the
> indication that those servers are not reachable.
>
> For example Output should like this:
>
> IP address   Last restart time
> 10.10.10.1   20070331115922.500000-240
> 10.10.10.2   Not reachable

> I like to take the output to an excel file . Restart time should be in the
> second cell.
>
> Current running script:
> ---------------------------
> On error resume Next
> Const ForReading = 1
> Const ForAppending = 8
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.OpenTextFile _
>     ("C:\servers.txt", ForReading)
>
> Set objTextFile1 = objFSO.OpenTextFile _
>     ("C:\last_reboot.csv", ForAppending, True)
>
> Do Until objTextFile.AtEndOfStream
>     strNextLine = objTextFile.Readline
>     arrServiceList = Split(strNextLine , ",")
>
>
> strComputer = arrServiceList(0)

> Set objWMIService = GetObject("winmgmts:" & _
> "{impersonationLevel=impersonate}!\\" & _
> strComputer & "\root\cimv2")
>
>
> Set colOS = objWMIService.ExecQuery _
> ("SELECT * FROM Win32_OperatingSystem")
>
> For Each objOS in colOS
> objTextFile1.Writeline arrServiceList(0) & vbtab & objOS.LastBootUpTime & vtab
> Next
>
> Loop
>
>
> ----------------------
>
> Can you please help me out.
>
> Regards,
> George
>
>

Hi George,

I added a ping:

'--------------------------------------------
On error resume Next
Const ForReading = 1
Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
     ("C:\servers.txt", ForReading)

Set objTextFile1 = objFSO.OpenTextFile _
     ("C:\last_reboot.csv", ForAppending, True)

Do Until objTextFile.AtEndOfStream
     strNextLine = objTextFile.Readline
     arrServiceList = Split(strNextLine , ",")


strComputer = arrServiceList(0)


Set objWMIService = GetObject("winmgmts:\\" & "." & "\root\cimv2")
Set colPings = objWMIService.ExecQuery ("Select * From Win32_PingStatus
where Address = '" & strComputer & "' AND Timeout=100")
For Each objStatus in colPings
     If IsNull(objStatus.StatusCode) or objStatus.StatusCode <> 0 Then
         IsOnline = False
     Else
         IsOnline = True
     End If
Next


If IsOnline Then
   Set objWMIService = GetObject("winmgmts:" & _
   "{impersonationLevel=impersonate}!\\" & _
   strComputer & "\root\cimv2")


   Set colOS = objWMIService.ExecQuery _
   ("SELECT * FROM Win32_OperatingSystem")

   For Each objOS in colOS
     objTextFile1.Writeline arrServiceList(0) & vbtab &
objOS.LastBootUpTime & vtab
   Next
else
     objTextFile1.Writeline arrServiceList(0) & vbtab & "Not reachable"
& vtab
end if

Loop
'--------------------------------------------
Author
2 Apr 2007 12:08 PM
George
Hi Marcus,

Thanks. I had run this script. But not getting the desired output. Ping
status shows as 'Not reachable ' always.
Can please suggest on this.

Regards,
George.


Show quote
"Marcus Schmitt" wrote:

> George schrieb:
> > Hi ,
> >
> > I am running a script to find the last restart time for a group of servers.
> > This script reads the server names from a text file and connect to that
> > server and returns the last restart time. This info will be written to a
> > file. Attached at the end of this.
> >
> > But some of the servers will be not reachable/accessable. I want the
> > indication that those servers are not reachable.
> >
> > For example Output should like this:
> >
> > IP address   Last restart time
> > 10.10.10.1   20070331115922.500000-240
> > 10.10.10.2   Not reachable
> > 
> > I like to take the output to an excel file . Restart time should be in the
> > second cell.
> >
> > Current running script:
> > ---------------------------
> > On error resume Next
> > Const ForReading = 1
> > Const ForAppending = 8
> >
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > Set objTextFile = objFSO.OpenTextFile _
> >     ("C:\servers.txt", ForReading)
> >
> > Set objTextFile1 = objFSO.OpenTextFile _
> >     ("C:\last_reboot.csv", ForAppending, True)
> >
> > Do Until objTextFile.AtEndOfStream
> >     strNextLine = objTextFile.Readline
> >     arrServiceList = Split(strNextLine , ",")
> >
> >
> > strComputer = arrServiceList(0)
> > 
> > Set objWMIService = GetObject("winmgmts:" & _
> > "{impersonationLevel=impersonate}!\\" & _
> > strComputer & "\root\cimv2")
> >
> >
> > Set colOS = objWMIService.ExecQuery _
> > ("SELECT * FROM Win32_OperatingSystem")
> >
> > For Each objOS in colOS
> > objTextFile1.Writeline arrServiceList(0) & vbtab & objOS.LastBootUpTime & vtab
> > Next
> >
> > Loop
> >
> >
> > ----------------------
> >
> > Can you please help me out.
> >
> > Regards,
> > George
> >
> >
>
> Hi George,
>
> I added a ping:
>
> '--------------------------------------------
> On error resume Next
> Const ForReading = 1
> Const ForAppending = 8
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.OpenTextFile _
>      ("C:\servers.txt", ForReading)
>
> Set objTextFile1 = objFSO.OpenTextFile _
>      ("C:\last_reboot.csv", ForAppending, True)
>
> Do Until objTextFile.AtEndOfStream
>      strNextLine = objTextFile.Readline
>      arrServiceList = Split(strNextLine , ",")
>
>
> strComputer = arrServiceList(0)
>
>
> Set objWMIService = GetObject("winmgmts:\\" & "." & "\root\cimv2")
> Set colPings = objWMIService.ExecQuery ("Select * From Win32_PingStatus
> where Address = '" & strComputer & "' AND Timeout=100")
> For Each objStatus in colPings
>      If IsNull(objStatus.StatusCode) or objStatus.StatusCode <> 0 Then
>          IsOnline = False
>      Else
>          IsOnline = True
>      End If
> Next
>
>
> If IsOnline Then
>    Set objWMIService = GetObject("winmgmts:" & _
>    "{impersonationLevel=impersonate}!\\" & _
>    strComputer & "\root\cimv2")
>
>
>    Set colOS = objWMIService.ExecQuery _
>    ("SELECT * FROM Win32_OperatingSystem")
>
>    For Each objOS in colOS
>      objTextFile1.Writeline arrServiceList(0) & vbtab &
> objOS.LastBootUpTime & vtab
>    Next
> else
>      objTextFile1.Writeline arrServiceList(0) & vbtab & "Not reachable"
> & vtab
> end if
>
> Loop
> '--------------------------------------------
>
>
>
Author
3 Apr 2007 5:34 AM
Marcus Schmitt
Hi George,

don't know why - I've testet it in our network and it works.
What happens if you ping of the machine in the dos prompt ?
Try to use only the ping lines as new script for testing.

Marcus





George schrieb:
Show quote
> Hi Marcus,
>
> Thanks. I had run this script. But not getting the desired output. Ping
> status shows as 'Not reachable ' always.
> Can please suggest on this.
>
> Regards,
> George.
>
>
> "Marcus Schmitt" wrote:
>
>> George schrieb:
>>> Hi ,
>>>
>>> I am running a script to find the last restart time for a group of servers.
>>> This script reads the server names from a text file and connect to that
>>> server and returns the last restart time. This info will be written to a
>>> file. Attached at the end of this.
>>>
>>> But some of the servers will be not reachable/accessable. I want the
>>> indication that those servers are not reachable.
>>>
>>> For example Output should like this:
>>>
>>> IP address   Last restart time
>>> 10.10.10.1   20070331115922.500000-240
>>> 10.10.10.2   Not reachable
>>> 
>>> I like to take the output to an excel file . Restart time should be in the
>>> second cell.
>>>
>>> Current running script:
>>> ---------------------------
>>> On error resume Next
>>> Const ForReading = 1
>>> Const ForAppending = 8
>>>
>>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>>> Set objTextFile = objFSO.OpenTextFile _
>>>     ("C:\servers.txt", ForReading)
>>>
>>> Set objTextFile1 = objFSO.OpenTextFile _
>>>     ("C:\last_reboot.csv", ForAppending, True)
>>>
>>> Do Until objTextFile.AtEndOfStream
>>>     strNextLine = objTextFile.Readline
>>>     arrServiceList = Split(strNextLine , ",")
>>>
>>>
>>> strComputer = arrServiceList(0)
>>> 
>>> Set objWMIService = GetObject("winmgmts:" & _
>>> "{impersonationLevel=impersonate}!\\" & _
>>> strComputer & "\root\cimv2")
>>>
>>>
>>> Set colOS = objWMIService.ExecQuery _
>>> ("SELECT * FROM Win32_OperatingSystem")
>>>
>>> For Each objOS in colOS
>>> objTextFile1.Writeline arrServiceList(0) & vbtab & objOS.LastBootUpTime & vtab
>>> Next
>>>
>>> Loop
>>>
>>>
>>> ----------------------
>>>
>>> Can you please help me out.
>>>
>>> Regards,
>>> George
>>>
>>>
>> Hi George,
>>
>> I added a ping:
>>
>> '--------------------------------------------
>> On error resume Next
>> Const ForReading = 1
>> Const ForAppending = 8
>>
>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>> Set objTextFile = objFSO.OpenTextFile _
>>      ("C:\servers.txt", ForReading)
>>
>> Set objTextFile1 = objFSO.OpenTextFile _
>>      ("C:\last_reboot.csv", ForAppending, True)
>>
>> Do Until objTextFile.AtEndOfStream
>>      strNextLine = objTextFile.Readline
>>      arrServiceList = Split(strNextLine , ",")
>>
>>
>> strComputer = arrServiceList(0)
>>
>>
>> Set objWMIService = GetObject("winmgmts:\\" & "." & "\root\cimv2")
>> Set colPings = objWMIService.ExecQuery ("Select * From Win32_PingStatus
>> where Address = '" & strComputer & "' AND Timeout=100")
>> For Each objStatus in colPings
>>      If IsNull(objStatus.StatusCode) or objStatus.StatusCode <> 0 Then
>>          IsOnline = False
>>      Else
>>          IsOnline = True
>>      End If
>> Next
>>
>>
>> If IsOnline Then
>>    Set objWMIService = GetObject("winmgmts:" & _
>>    "{impersonationLevel=impersonate}!\\" & _
>>    strComputer & "\root\cimv2")
>>
>>
>>    Set colOS = objWMIService.ExecQuery _
>>    ("SELECT * FROM Win32_OperatingSystem")
>>
>>    For Each objOS in colOS
>>      objTextFile1.Writeline arrServiceList(0) & vbtab &
>> objOS.LastBootUpTime & vtab
>>    Next
>> else
>>      objTextFile1.Writeline arrServiceList(0) & vbtab & "Not reachable"
>> & vtab
>> end if
>>
>> Loop
>> '--------------------------------------------
>>
>>
>>
Author
3 Apr 2007 2:00 PM
George
Thanks Marcus. The script is giving the desired output in our network
without any change in code.
Thanks for your help.

George.

Show quote
"Marcus Schmitt" wrote:

> Hi George,
>
> don't know why - I've testet it in our network and it works.
> What happens if you ping of the machine in the dos prompt ?
> Try to use only the ping lines as new script for testing.
>
> Marcus
>
>
>
>
>
> George schrieb:
> > Hi Marcus,
> >
> > Thanks. I had run this script. But not getting the desired output. Ping
> > status shows as 'Not reachable ' always.
> > Can please suggest on this.
> >
> > Regards,
> > George.
> >
> >
> > "Marcus Schmitt" wrote:
> >
> >> George schrieb:
> >>> Hi ,
> >>>
> >>> I am running a script to find the last restart time for a group of servers.
> >>> This script reads the server names from a text file and connect to that
> >>> server and returns the last restart time. This info will be written to a
> >>> file. Attached at the end of this.
> >>>
> >>> But some of the servers will be not reachable/accessable. I want the
> >>> indication that those servers are not reachable.
> >>>
> >>> For example Output should like this:
> >>>
> >>> IP address   Last restart time
> >>> 10.10.10.1   20070331115922.500000-240
> >>> 10.10.10.2   Not reachable
> >>> 
> >>> I like to take the output to an excel file . Restart time should be in the
> >>> second cell.
> >>>
> >>> Current running script:
> >>> ---------------------------
> >>> On error resume Next
> >>> Const ForReading = 1
> >>> Const ForAppending = 8
> >>>
> >>> Set objFSO = CreateObject("Scripting.FileSystemObject")
> >>> Set objTextFile = objFSO.OpenTextFile _
> >>>     ("C:\servers.txt", ForReading)
> >>>
> >>> Set objTextFile1 = objFSO.OpenTextFile _
> >>>     ("C:\last_reboot.csv", ForAppending, True)
> >>>
> >>> Do Until objTextFile.AtEndOfStream
> >>>     strNextLine = objTextFile.Readline
> >>>     arrServiceList = Split(strNextLine , ",")
> >>>
> >>>
> >>> strComputer = arrServiceList(0)
> >>> 
> >>> Set objWMIService = GetObject("winmgmts:" & _
> >>> "{impersonationLevel=impersonate}!\\" & _
> >>> strComputer & "\root\cimv2")
> >>>
> >>>
> >>> Set colOS = objWMIService.ExecQuery _
> >>> ("SELECT * FROM Win32_OperatingSystem")
> >>>
> >>> For Each objOS in colOS
> >>> objTextFile1.Writeline arrServiceList(0) & vbtab & objOS.LastBootUpTime & vtab
> >>> Next
> >>>
> >>> Loop
> >>>
> >>>
> >>> ----------------------
> >>>
> >>> Can you please help me out.
> >>>
> >>> Regards,
> >>> George
> >>>
> >>>
> >> Hi George,
> >>
> >> I added a ping:
> >>
> >> '--------------------------------------------
> >> On error resume Next
> >> Const ForReading = 1
> >> Const ForAppending = 8
> >>
> >> Set objFSO = CreateObject("Scripting.FileSystemObject")
> >> Set objTextFile = objFSO.OpenTextFile _
> >>      ("C:\servers.txt", ForReading)
> >>
> >> Set objTextFile1 = objFSO.OpenTextFile _
> >>      ("C:\last_reboot.csv", ForAppending, True)
> >>
> >> Do Until objTextFile.AtEndOfStream
> >>      strNextLine = objTextFile.Readline
> >>      arrServiceList = Split(strNextLine , ",")
> >>
> >>
> >> strComputer = arrServiceList(0)
> >>
> >>
> >> Set objWMIService = GetObject("winmgmts:\\" & "." & "\root\cimv2")
> >> Set colPings = objWMIService.ExecQuery ("Select * From Win32_PingStatus
> >> where Address = '" & strComputer & "' AND Timeout=100")
> >> For Each objStatus in colPings
> >>      If IsNull(objStatus.StatusCode) or objStatus.StatusCode <> 0 Then
> >>          IsOnline = False
> >>      Else
> >>          IsOnline = True
> >>      End If
> >> Next
> >>
> >>
> >> If IsOnline Then
> >>    Set objWMIService = GetObject("winmgmts:" & _
> >>    "{impersonationLevel=impersonate}!\\" & _
> >>    strComputer & "\root\cimv2")
> >>
> >>
> >>    Set colOS = objWMIService.ExecQuery _
> >>    ("SELECT * FROM Win32_OperatingSystem")
> >>
> >>    For Each objOS in colOS
> >>      objTextFile1.Writeline arrServiceList(0) & vbtab &
> >> objOS.LastBootUpTime & vtab
> >>    Next
> >> else
> >>      objTextFile1.Writeline arrServiceList(0) & vbtab & "Not reachable"
> >> & vtab
> >> end if
> >>
> >> Loop
> >> '--------------------------------------------
> >>
> >>
> >>
>

AddThis Social Bookmark Button