Skip to content

Commit

Permalink
Merge pull request #42 from hic-infra/quserhmmm
Browse files Browse the repository at this point in the history
Fix for < 24 hours
  • Loading branch information
AaronJackson authored Aug 2, 2024
2 parents af235a2 + 45f93a8 commit 0305865
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion modules/autohibernate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ Set-Content $idleScript @"
# i.e. "days.hours:minutes" or just "hours:minutes"
`$idleTime = (`$session.'IDLE TIME').Replace('+', '.')
if (`$idleTime -eq ".") { `$idleTime = 0 }
if (`$idleTime -notmatch "\.") { `$idleTime = "0.0:`$idleTime" }
if (`$idleTime -notmatch ":") { `$idleTime = "0:`$idleTime" }
# A single number will be cast to days.
# H:M (or HH:MM) will be cast correctly.
`$idleTime = [TimeSpan]`$idleTime
if (`$idleTime.TotalMinutes -ge $Env:AUTOHIBERNATE_TIME) {
Stop-Computer -ComputerName localhost -Force
}
"@


$action = New-ScheduledTaskAction -Execute powershell.exe `
-Argument "-File $idleScript"
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) `
Expand Down

0 comments on commit 0305865

Please sign in to comment.