hopefully this is the last test
This commit is contained in:
@@ -1,21 +1,11 @@
|
|||||||
Function Restart-EndpointOnUptime ([int]$MaxUptimeHours) {
|
Function Restart-EndpointOnUptime ([int]$MaxUptimeHours) {
|
||||||
|
|
||||||
# Check the last boot up time
|
# Get the last boot up time as a DateTime
|
||||||
#$LastBootUpTime =
|
|
||||||
$LastBootUpTime = [Management.ManagementDateTimeConverter]::ToDateTime($(Get-WmiObject -Class Win32_OperatingSystem -ErrorAction Stop | Select-Object -ExpandProperty LastBootUpTime))
|
$LastBootUpTime = [Management.ManagementDateTimeConverter]::ToDateTime($(Get-WmiObject -Class Win32_OperatingSystem -ErrorAction Stop | Select-Object -ExpandProperty LastBootUpTime))
|
||||||
|
|
||||||
|
|
||||||
# Calculate the difference in hours
|
# If the number of hours the system has been up is greater than $MaxUptimeHours, restart the endpoint
|
||||||
#$CurrentTime =
|
|
||||||
#$TimeDifference =
|
|
||||||
#$DifferenceInHours =
|
|
||||||
|
|
||||||
# Check if the difference is greater than $MaxUptimeHours
|
|
||||||
If ($($(Get-Date) - $LastBootUpTime).TotalHours -gt $MaxUptimeHours) {
|
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."
|
Write-Output "Restarting computer because it has not been restarted in the last ${MaxUptimeHours} hours."
|
||||||
#Restart-Computer
|
#Restart-Computer -Force
|
||||||
} Else {
|
|
||||||
Write-Output "No need to restart. The last restart was within ${MaxUptimeHours} hours."
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user