testing errors
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
Function Restart-EndpointOnUptime ([int]$MaxUptimeHours) {
|
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
|
Try { $LastBootUpTime = Get-WmiObject -Class Win32_OperatingSystem1 -ErrorAction SilentlyContinue | Select-Object -ExpandProperty LastBootUpTime }
|
||||||
|
Catch { Write-Error $_.Exception.Message }
|
||||||
$LastBootUpTime = [Management.ManagementDateTimeConverter]::ToDateTime($LastBootUpTime)
|
$LastBootUpTime = [Management.ManagementDateTimeConverter]::ToDateTime($LastBootUpTime)
|
||||||
|
|
||||||
# Calculate the difference in hours
|
# Calculate the difference in hours
|
||||||
@@ -13,7 +14,7 @@ Function Restart-EndpointOnUptime ([int]$MaxUptimeHours) {
|
|||||||
If ($DifferenceInHours -gt $MaxUptimeHours) {
|
If ($DifferenceInHours -gt $MaxUptimeHours) {
|
||||||
# Restart the computer
|
# 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
|
||||||
} Else {
|
} Else {
|
||||||
Write-Output "No need to restart. The last restart was within ${MaxUptimeHours} hours."
|
Write-Output "No need to restart. The last restart was within ${MaxUptimeHours} hours."
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user