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.

Deploy using WOL and shut down only machines that were offline.

Is it possible to do a deployment to a group of machines, and use WOL to wake up machines that are offline, BUT after the deployment, shut down only those machines that were offline and got up with the WOL?

Thanks.

0

Comments

3 comments
Date Votes
  • I think you can do this by looking at uptime.

    1. Create a PowerShell step and make it Step 1.
      # https://blogs.technet.microsoft.com/heyscriptingguy/2013/03/27/powertip-get-the-last-boot-time-with-powershell/
      $Uptime_Raw = Get-WmiObject Win32_OperatingSystem
      $Uptime_Converted = $Uptime_Raw.ConvertToDateTime($Uptime_Raw.LastBootUpTime)
      $Uptime = ( Get-Date ) - ( Get-Date $Uptime_Converted )

      Write-Output "Uptime: $($Uptime.TotalHours) hours"

      if ( $Uptime.TotalHours -lt 1 ) {

      # Target was probably woken by WoL
      New-ItemProperty-Path "HKLM:\HARDWARE"-Name "Should I Turn Off"-PropertyType "String"-Value "Yes"-Force

      } else {

      # Target was probably not woken by WoL
      New-ItemProperty-Path "HKLM:\HARDWARE"-Name "Should I Turn Off"-PropertyType "String"-Value "No"-Force

      }
    2. Create a Reboot step and make it the last step. Check for the box labeled "Shutdown Only". Set the Registry Condition like this:


    0
  • Hi Colby, thanks for your solution, i'll give it a try. 

    I have no experience in scripting and i have 2 questions. From what i see you use the LastBootUptime property to check last boot time and...

    Question 1. do you write a new entry on the registry to check it on step 2?

    Question 2. The condition is if boot time is less than 1 hour?

     

    Thanks again.

    0
    1. Yes.
    2. Yes.
    0