-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error in detect-reboot script #32
Comments
Considering it's now October 10th, 2023 (more than 6 months since you opened this issue), I'd imagine you've either figured out how to fix the issue or have moved onto something else entirely. Regardless, I just came across this repository a few minutes ago and almost immediately noticed the same issue(s) you're describing. I rewrote the entire PowerShell script but I'll just share the fix for the specific problem you asked for here: $ProgressPreference = 'SilentlyContinue'
# Define how often you want your devices to be rebooted
$RebootDeadlineInDays = 7
# Retrieve the Operating System's "Uptime"
$Uptime = Get-ComputerInfo -Property OSUptime | Select-Object OSUptime
if ($Uptime.OSUptime.Days -ge $RebootDeadlineInDays) {
Write-Host "Operating System has been running for $($Uptime.OSUptime.Days) days! Reboot required."
Exit 0
} else {
Write-Host "Operating System was rebooted $($Uptime.OSUptime.Days) days ago! Compliance check: Pass."
Exit 1
} Hope that helps! For what it's worth, you can choose to use different measurements of time ("Hours", "Minutes", etc.) by selecting the associated property in the "$Uptime" variable. For example, if you wanted to determine how many hours ago a device rebooted, you could use the following code: $UptimeInDays = $Uptime.OSUptime.Days
$UptimeInHours = $Uptime.OSUptime.Hours
if ($UptimeInDays -eq 0) {
Write-Host "Device was rebooted $UptimeInHours hours ago!"
} |
Thanks for the code, but I think this does not take Fast Boot into consideration. |
That's fair. I have Fast Startup disabled across all devices in our environment so that's a use-case I never would've come across. Out of curiosity, what's your result when using the following? $DeviceLastBootupTime = Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty LastBootupTime
$TimeDifference = (Get-Date) - $DeviceLastBootupTime
Write-Host "Device has been online for $($TimeDifference.Days) days, $($TimeDifference.Hours) hours and $($TimeDifference.Minutes) minutes." EDITIn all fairness*, however, technically your device hasn’t rebooted in 12 days. With Fast Startup enabled, your device is simply going to sleep and waking up from hibernation. |
The output is 'Device has been online for 13 days, 2 hours and 15 minutes.'. I know it technically has not rebooted since 13 days since it goes into hibernation, that's why we also disable fast boot so updates get installed properly. Tried pasting my script again, but it won't get any better than this. Hope you can get the output from it you need with and without fast boot enabled
|
The script used to detect the last time a system was restarted gives an error on my Windows 10 build (19045.2728 Dutch)
https://github.com/JayRHa/EndpointAnalyticsRemediationScripts/blob/main/Toast-RebootMessage/detect-reboot.ps1
The error is
`
Cannot convert value "1680444208,84456" to type "System.Int32". Error: "De indeling van de invoertekenreeks is onjuist."
At line:1 char:1
It's triggered by the command $diff = $now - $poweron, but the problem is probably related to the values of $now and $poweron.
The returned values in the original script are
1680444208,84456
for $now and1680444197,71884
for $differ.If you replace the , with a . by changing the $now and $differ to these commands, it works.
$now = (Get-Date -UFormat "%s" -Date (Get-Date)) -replace (",",".")
$poweron = (Get-Date -UFormat "%s" -Date (Get-Process -Id $pid).StartTime) -replace (",",".")
New values are
1680444208.84456
for $now and1680444197.71884
for $differ and then the calculations work.I think it has something to do with the region we run in our enviroment Windows (Dutch), so the characters used for numbering might differ.
The text was updated successfully, but these errors were encountered: