Important Notice: On February 29th, this community was put into read-only mode. All existing posts will remain but customers are unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

Create collections based on uptime?

My users have a horrible job at shutting down their machines. I'd like to create a dynamic collection based on the uptime reported by inventory scans. 

Something like "If computer uptime >= 1 day" . I'd tie this to a reboot package in Deploy. 

 

Is this possible?

0

Comments

8 comments
Date Votes
  • See attached screenshot.

    0
  • How can I see this screenshot?

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

    Computer | Boot Time | Before | 1 day ago

     

    1
  • Thanks!

    0
  • Thanks!

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

    0
  • 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
  • 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
  • Very elegant solution, Colby. Appreciate the assistance!

    0