Create collections based on uptime?

Comments

8 comments

  • Bouma, Colby

    See attached screenshot.

    0
    Comment actions Permalink
  • Ron Masters

    How can I see this screenshot?

    0
    Comment actions Permalink
  • Colby Bouma

    Huh, it disappeared. Here's a new one:

    Computer | Boot Time | Before | 1 day ago

     

    1
    Comment actions Permalink
  • Ron Masters

    Thanks!

    0
    Comment actions Permalink
  • Ron Masters

    Thanks!

    I was hoping to pull this off solely in PDQ Deploy... but looks like Inventory makes the job easier!

    0
    Comment actions Permalink
  • Colby Bouma

    You can do it in Deploy as well. This script will cause the deployment to fail if the uptime is less than 1 day, but you could also save the uptime into the Registry and use a Registry Condition on the next step.

    # Grab the WMI object that contains LastBootUpTime
    $OS_Object = Get-WmiObject Win32_OperatingSystem

    # Convert LastBootUpTime to a DateTime object
    # https://ss64.com/ps/syntax-get-uptime.html
    $Last_Boot_Time = $OS_Object.ConvertToDateTime($OS_Object.LastBootUpTime)

    # Calculate uptime
    $Uptime = ( Get-Date ) - $Last_Boot_Time
    Write-Output $Uptime

    if ( $Uptime.Days -lt 1 ) {

        Exit 1

    }
    1
    Comment actions Permalink
  • Colby Bouma

    Here's how you would do it with a Registry Condition.

    1. Create a PowerShell Step and make it Step 1.
      # Grab the WMI object that contains LastBootUpTime
      $OS_Object = Get-WmiObject Win32_OperatingSystem

      # Convert LastBootUpTime to a DateTime object
      # https://ss64.com/ps/syntax-get-uptime.html
      $Last_Boot_Time = $OS_Object.ConvertToDateTime($OS_Object.LastBootUpTime)

      # Calculate uptime
      $Uptime = ( Get-Date ) - $Last_Boot_Time
      Write-Output $Uptime

      New-ItemProperty -Path "HKLM:\HARDWARE" -Name "System Uptime" -PropertyType "Dword" -Value $Uptime.Days -Force
    2. Set the Registry Condition of all successive steps like this:


    1
    Comment actions Permalink
  • Ron Masters

    Very elegant solution, Colby. Appreciate the assistance!

    0
    Comment actions Permalink

Please sign in to leave a comment.