diff --git a/Restart-EndpointOnUptime.ps1 b/Restart-EndpointOnUptime.ps1 index f7b9614..759790c 100644 --- a/Restart-EndpointOnUptime.ps1 +++ b/Restart-EndpointOnUptime.ps1 @@ -1,21 +1,11 @@ Function Restart-EndpointOnUptime ([int]$MaxUptimeHours) { - # Check the last boot up time - #$LastBootUpTime = + # Get the last boot up time as a DateTime $LastBootUpTime = [Management.ManagementDateTimeConverter]::ToDateTime($(Get-WmiObject -Class Win32_OperatingSystem -ErrorAction Stop | Select-Object -ExpandProperty LastBootUpTime)) - - # Calculate the difference in hours - #$CurrentTime = - #$TimeDifference = - #$DifferenceInHours = - - # Check if the difference is greater than $MaxUptimeHours + # If the number of hours the system has been up is greater than $MaxUptimeHours, restart the endpoint If ($($(Get-Date) - $LastBootUpTime).TotalHours -gt $MaxUptimeHours) { - # Restart the computer Write-Output "Restarting computer because it has not been restarted in the last ${MaxUptimeHours} hours." - #Restart-Computer - } Else { - Write-Output "No need to restart. The last restart was within ${MaxUptimeHours} hours." + #Restart-Computer -Force } } \ No newline at end of file