rmm-scripts/lastreboot.ps1
2023-06-05 11:51:38 -07:00

26 lines
702 B
PowerShell

#* = Required
#* -days <int> (Max days)
#
#-returncode (Prints return code 0 if the last bootup time is less than 4 days than the current date, and 1 if it's over 4 days.)
[CmdletBinding()]
param (
[switch]$returncode,
[int]$days = 4
)
$os = Get-WmiObject Win32_OperatingSystem
$lastBootupTime = $os.ConvertToDateTime($os.LastBootUpTime)
$daysSinceLastBootup = (Get-Date) - $lastBootupTime | select -ExpandProperty Days
$lastBootupTimeFormatted = $lastBootupTime.ToString("MM/dd/yy hh:mm:ss")
if ($daysSinceLastBootup -lt $days) {
Write-Host "$lastBootupTimeFormatted"
if ($returncode) { exit 0 }
}
else {
Write-Host "$lastBootupTimeFormatted"
if ($returncode) { exit 1 }
}