added function Restart-EndpointOnUptime
This commit is contained in:
@@ -873,5 +873,23 @@ Function Uninstall-MSI ([Parameter(ValueFromPipeline=$true)][string[]]$APP_NAMES
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Reboot an endpoint based on the amount of time it has been running without a reboot
|
||||||
|
Function Restart-EndpointOnUptime ([timespan]$MaxUptime) {
|
||||||
|
|
||||||
|
# Get the length of time the endpoint has been running without restart
|
||||||
|
Try { $LastBootTime = (Get-CimInstance -ClassName Win32_OperatingSystem -ErrorAction Stop).LastBootUpTime }
|
||||||
|
Catch { LogErr $_.Exception.Message ; Exit }
|
||||||
|
|
||||||
|
# Get the difference between the endpoint uptime and the current time
|
||||||
|
$Delta = New-TimeSpan -Start $LastBootTime -End $(Get-Date)
|
||||||
|
|
||||||
|
# Stop the function if the endpoint has not exceeded $MaxUptime
|
||||||
|
If ( $Delta -lt $MaxUptime ) { Exit }
|
||||||
|
|
||||||
|
# Reboot the endpoint
|
||||||
|
Try { Restart-Computer -Force -ErrorAction Stop }
|
||||||
|
Catch { LogErr $_.Exception.Message }
|
||||||
|
}
|
||||||
|
|
||||||
Setup-MSPDirectories
|
Setup-MSPDirectories
|
||||||
Setup-LogFile
|
Setup-LogFile
|
||||||
Reference in New Issue
Block a user