Changelog
[4.0.0] - 2026-05-23
Added
- KeepAwake Mode: New
-KeepAwake/-KeepDisplayparameters callSetThreadExecutionStateso Windows itself keeps the system (and optionally the display) awake. Ideal for presentations, long downloads, and remote sessions. The execution-state flag is cleared on exit. - Idle Guard for Nudge Mode: New
-OnlyWhenIdleand-IdleSecondsparameters useGetLastInputInfoto skip a cycle if the user has been active recently, so the cursor no longer jumps while you are typing or clicking. - INPUTS / OUTPUTS / LINK Help Sections: Comment-based help now documents the lack of pipeline support and links to the GitHub repo, so
Get-Help .\StayActive.ps1 -Onlineworks.
Changed
- Modern Win32 Input API: Mouse input migrated from the superseded
mouse_eventtoSendInput. Signeddx/dyremoves theuinttwo's-complement workaround that the old code needed to express negative motion. - Output Streams: Status output now uses
Write-Information(the Information stream) andWrite-Progressinstead ofWrite-Host, so output can be redirected, suppressed, or captured like any other PowerShell stream. - Help System: Replaced the custom
-Helpswitch with comment-based help; useGet-Help .\StayActive.ps1 -Fullinstead. - Synopsis: Tightened to a single sentence in the conventional third-person present tense, matching built-in cmdlet style.
Improved
- Idempotent Interop:
Add-Typeis now guarded so re-running the script in the same PowerShell session no longer fails on duplicate CLR types. Native types live in their ownStayActivenamespace to avoid global collisions. - Native Error Surfacing:
GetCursorPosandGetLastInputInforeturn values are checked and any Win32 error is surfaced viaGetLastWin32Errorinstead of silently returning a zeroedPOINT. - Cleaner Verbose Detection:
-Verboseis now detected via$PSBoundParameters.ContainsKey('Verbose'), so a globally set$VerbosePreferenceno longer triggers the script's per-cycle countdown unintentionally. - Verbose Countdown: Now uses
Write-Progresswith-SecondsRemaininginstead of writing a line per second.
Security
- Code Signing: Script is digitally signed with Extended Validation (EV) Code Signing Certificate.
- Constrained Language Mode Detection: Script exits early with an actionable message if PowerShell is running under AppLocker / WDAC
ConstrainedLanguagemode, instead of failing partway through with a confusingAdd-Typeerror. - Platform Guard: On PowerShell 7, the script checks
$IsWindowsand exits with a pointer tocaffeinate(macOS) orsystemd-inhibit(Linux) instead of crashing onuser32.dll.
Breaking Changes
-HelpRemoved: UseGet-Help .\StayActive.ps1 -Fullor-Onlineinstead. Anyone scripting.\StayActive.ps1 -Helpneeds to update.- Output Streams: Status no longer goes to the host directly via
Write-Host. Scripts that captured stdout will need to use-InformationAction Continueor the6>redirection operator. - Parameter Sets:
-MoveInterval,-SmallMove,-OnlyWhenIdle,-IdleSecondsbelong to theNudgeset;-KeepAwake,-KeepDisplaybelong to theKeepAwakeset. Mixing them produces a parameter-set error.
Migration Guide
From v3.1.0 to v4.0.0:
- Replace
.\StayActive.ps1 -HelpwithGet-Help .\StayActive.ps1 -Full - If you piped or redirected the script's output, switch from stdout capture to
6>(Information stream) or pass-InformationAction SilentlyContinueto mute it - For "keep the machine awake" use cases (presentations, downloads), prefer the new
-KeepAwakeover the default Nudge mode - For "stay marked active in Teams" use cases, keep using the default (Nudge), and consider adding
-OnlyWhenIdleso the cursor only moves when you have actually walked away
Notes
- Nudge mode (the original behaviour) remains the default; passing no parameters works exactly as before
- KeepAwake is a power-management hint and will not keep Teams or similar presence-aware apps from marking you away — use Nudge for that
- Requires
FullLanguagemode; the script exits with a clear message under Constrained Language Mode - Tested on Windows PowerShell 5.1 and PowerShell 7+