From 3bb28f34c17504554649c18c9dcfbae0837697e3 Mon Sep 17 00:00:00 2001 From: David Yoder Date: Wed, 28 Feb 2024 14:05:46 -0500 Subject: [PATCH] testing more errors --- Restart-EndpointOnUptime.ps1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Restart-EndpointOnUptime.ps1 b/Restart-EndpointOnUptime.ps1 index d2c5964..48030d7 100644 --- a/Restart-EndpointOnUptime.ps1 +++ b/Restart-EndpointOnUptime.ps1 @@ -1,9 +1,12 @@ Function Restart-EndpointOnUptime ([int]$MaxUptimeHours) { # Check the last boot up time - Try { $LastBootUpTime = Get-WmiObject -Class Win32_OperatingSystem1 -ErrorAction SilentlyContinue | Select-Object -ExpandProperty LastBootUpTime } - Catch { Write-Error $_.Exception.Message } - $LastBootUpTime = [Management.ManagementDateTimeConverter]::ToDateTime($LastBootUpTime) + Try { + $LastBootUpTime = Get-WmiObject -Class Win32_OperatingSystem1 -ErrorAction SilentlyContinue | Select-Object -ExpandProperty LastBootUpTime + $LastBootUpTime = [Management.ManagementDateTimeConverter]::ToDateTime($LastBootUpTime) + } + Catch { Write-Error $_.Exception.Message ; Write-Output "Cannot restart this computer" ; Exit } + # Calculate the difference in hours $CurrentTime = Get-Date