use int instead of timespan
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
Function Restart-EndpointOnUptime ([timespan]$MaxUptime) {
|
Function Restart-EndpointOnUptime ([int]$MaxUptimeHours) {
|
||||||
|
|
||||||
# Check the last boot up time
|
# Check the last boot up time
|
||||||
$LastBootUpTime = Get-WmiObject -Class Win32_OperatingSystem | Select-Object -ExpandProperty LastBootUpTime
|
$LastBootUpTime = Get-WmiObject -Class Win32_OperatingSystem | Select-Object -ExpandProperty LastBootUpTime
|
||||||
@@ -9,12 +9,12 @@ Function Restart-EndpointOnUptime ([timespan]$MaxUptime) {
|
|||||||
$TimeDifference = $CurrentTime - $LastBootUpTime
|
$TimeDifference = $CurrentTime - $LastBootUpTime
|
||||||
$DifferenceInHours = $TimeDifference.TotalHours
|
$DifferenceInHours = $TimeDifference.TotalHours
|
||||||
|
|
||||||
# Check if the difference is greater than $MaxUptime
|
# Check if the difference is greater than $MaxUptimeHours
|
||||||
If ($DifferenceInHours -gt $MaxUptime) {
|
If ($DifferenceInHours -gt $MaxUptimeHours) {
|
||||||
# Restart the computer
|
# Restart the computer
|
||||||
Write-Output "Restarting computer because it has not been restarted in the last ${MaxUptime} hours."
|
Write-Output "Restarting computer because it has not been restarted in the last ${MaxUptimeHours} hours."
|
||||||
#Restart-Computer
|
#Restart-Computer
|
||||||
} Else {
|
} Else {
|
||||||
Write-Output "No need to restart. The last restart was within ${MaxUptime} hours."
|
Write-Output "No need to restart. The last restart was within ${MaxUptimeHours} hours."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user