From 80877ded48d80f8dcbe02cb0e3b01cbbe85a32c2 Mon Sep 17 00:00:00 2001 From: David Yoder Date: Wed, 28 Feb 2024 14:10:55 -0500 Subject: [PATCH] ... --- Restart-EndpointOnUptime.ps1 | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Restart-EndpointOnUptime.ps1 b/Restart-EndpointOnUptime.ps1 index 7813987..81e1ae2 100644 --- a/Restart-EndpointOnUptime.ps1 +++ b/Restart-EndpointOnUptime.ps1 @@ -1,11 +1,8 @@ Function Restart-EndpointOnUptime ([int]$MaxUptimeHours) { # Check the last boot up time - Try { - $LastBootUpTime = Get-WmiObject -Class Win32_OperatingSystem1 -ErrorAction Stop | Select-Object -ExpandProperty LastBootUpTime - $LastBootUpTime = [Management.ManagementDateTimeConverter]::ToDateTime($LastBootUpTime) - } - Catch [Exception] { Write-Error $_.Exception.Message ; Write-Output "Cannot restart this computer" ; Exit } + $LastBootUpTime = Get-WmiObject -Class Win32_OperatingSystem1 -ErrorAction Stop | Select-Object -ExpandProperty LastBootUpTime + $LastBootUpTime = [Management.ManagementDateTimeConverter]::ToDateTime($LastBootUpTime) # Calculate the difference in hours