Checking up on Uptime

I recently wrote an article for the SAGE-AU Newsletter about how much I enjoy scripting using powershell. For the example code I made a script that would use WMI to query the uptime details of a server, and report back on servers that had been up for a minimum number of days.

I have tidied up the code, and it can be downloaded Here

The code now will check to see if the machine(s) are reachable before querying them (WMI has a nasty habit of waiting a long time otherwise. I also implement the QAD-GetComputer version of the script.

This script actually did come in useful this week, as the query found a disturbing number of machines that had been up for more than 90 days (and some more than 250 days) without being patched. Being Windows servers, you can usually safely bet that any server than has not been rebooted after 60 days has not been patched recently…

Work is now being done to rectify this.

3 thoughts on “Checking up on Uptime

  1. billy

    Hey the powershell script to grab licenses via powershell will come in handy, problem is I first need to change all the ILO DNS names (we use static IP’s, etc) first. I’ve had no luck really getting these to “automatically” update themselves in DNS and WINS isn’t really an option either…..

    I found this vbs script below but was wondering if you had something that can change the ILO name (subsystem name) according the the IP address (in bulk at one time of course :))
    THus far the script isn’t working, some issue with the array

    Any help you can provide is much appreciated!

    ‘ Riloes.ini must be formatted %nameoripofriloe%,%newdnsnameofriloe% must be separted by comma

    On error resume next

    Set Filesys = CreateObject(“Scripting.FileSystemObject”)
    Set WshShell = CreateObject(“Wscript.Shell”)
    Set WshNetwork = CreateObject(“Wscript.Network”)
    ScriptPath = Left(wscript.ScriptFullName,instrrev(wscript.ScriptFullName,”\”))

    ‘Input file
    Infile = “RILOES.ini”
    Logfile = “RILOE.xml”
    ‘XML Input
    RILOCMD = “insert.xml”
    ‘Output File
    Summary = “RILOES.LOG”
    strRILOEUser = “insertusernamehere”
    strRILOEPW = “replacewithrealpassword”

    ‘Open Log File
    Set Writefile = Filesys.CreateTextFile(Summary)

    ‘Open the file
    Set Readfile = Filesys.OpenTextFile(Infile, 1, false)

    ‘Get a line from the input file, ignoring semi-colon

    Do while Readfile.AtEndOfStream = False
    MyString = Readfile.ReadLine
    MyArray = split(MyString, “,” , -1, 1)
    RILOEName = MyArray (0)
    NewName = MyArray (1)

    Set objFSO = CreateObject(“Scripting.FileSystemObject”)
    Set objWshShell = CreateObject(“Wscript.Shell”)
    ‘Create Empty XML File
    Set XMLWrite = objFSO.CreateTextFile(RILOCMD)
    ‘Create XML File
    XMLWrite.Write “” & vbcrlf
    XMLWrite.Write “” & vbcrlf
    XMLWrite.Write “” & vbcrlf
    XMLWrite.Write “” & vbcrlf
    XMLWrite.Write “” & vbcrlf
    XMLWrite.Write “” & vbcrlf
    XMLWrite.Write “” & vbcrlf
    XMLWrite.Write “” & vbcrlf
    XMLWrite.Write “” & vbcrlf

    ‘If not comment, then execute configurator – logging to temp file
    wshShell.Run “cpqlocfg.exe -s ” & RILOEName & ” -l ” & Logfile & ” -f ” & RILOCMD,1,1

    ‘Open & Read Temp File
    Set Tempfile = Filesys.OpenTextFile(Logfile, 1, false)
    TempText= TempFile.Readall

    if Instr(TempText,Scriptpath & “cpqlocfg.exe: Script succeeded on ” & chr(34) & RILOENAME & “:443″ & chr(34))>=1 Then
    Writefile.Write RILOENAME & ” Configured correctly.” & vbcrlf
    Writefile.Write RILOENAME & ” configuration FAILED!” & vbcrlf
    end if

    ‘Close & Delete the temp file
    ‘Delete XML file to allow the Next one


    msgbox(“Script Complete. Log files are located at ” & scriptpath)


    1. practicaladmin Post author

      Hi Billy,

      Just a quick note to let you know I am working on this and should have something that will come very close to meeting your needs (and that you can modify accordingly).


    2. practicaladmin Post author

      Hi Billy,
      Please check out my new Blog Post:

      Whilst it will not do *exactly* what you need, you should be able to do a bit of minor modification to it to make it work. I’d probably do this by creating a variable containing the RIBCL Script which then contains a variable where you can specify the system name based on a rule that runs in the foreach loop.

      function FindSystemName { ... }
      foreach (device in list)
      $system = FindSystemName(Device)
      $command = ...$system...
      perl -s device -f $command

      Hope that all kind of makes sense, and gives you something to go by 🙂

Comments are closed.