testing more errors

This commit is contained in:
2024-02-28 14:05:46 -05:00
parent a3bd47580a
commit 3bb28f34c1
+6 -3
View File
@@ -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