initial commit

This commit is contained in:
2024-02-28 13:51:44 -05:00
parent 098c590084
commit 4c5f608457
+20
View File
@@ -0,0 +1,20 @@
Function Restart-EndpointOnUptime ([timespan]$MaxUptime) {
# Check the last boot up time
$LastBootUpTime = Get-WmiObject -Class Win32_OperatingSystem | Select-Object -ExpandProperty LastBootUpTime
$LastBootUpTime = [Management.ManagementDateTimeConverter]::ToDateTime($LastBootUpTime)
# Calculate the difference in hours
$CurrentTime = Get-Date
$TimeDifference = $CurrentTime - $LastBootUpTime
$DifferenceInHours = $TimeDifference.TotalHours
# Check if the difference is greater than $MaxUptime
If ($DifferenceInHours -gt $MaxUptime) {
# Restart the computer
Write-Output "Restarting computer because it has not been restarted in the last ${MaxUptime} hours."
#Restart-Computer
} Else {
Write-Output "No need to restart. The last restart was within ${MaxUptime} hours."
}
}