Skip to content

Add -Delay, -Reason to Stop-Computer #28163

Open

Description

@soroshsabz

Summary of the new feature / enhancement

Currently, the Stop-Computer cmdlet lacks native parameters for delayed shutdowns (-Timeout / -Delay) and audit-compliant shutdown reasons (-Reason / -Comment). System administrators who need to schedule maintenance with user grace periods or log structured reasons to the Windows Event Log (Event ID 1074) are forced to abandon idiomatic PowerShell and fall back to the legacy shutdown.exe command-line utility.

As a systems administrator managing Windows environments via PowerShell,

I want to specify a delay countdown, an audit reason, and a custom comment directly within the Stop-Computer cmdlet,

So that I can give active users advance notice before power-off and maintain accurate system event audit logs without relying on legacy shutdown.exe workarounds.

Proposed technical implementation details (optional)

  • -Timeout / -Delay [int]: Time to wait (in seconds) before initiating the shutdown/restart.
  • -Comment [string]: User-readable message or banner text displayed to users and recorded in the event log.
  • -Reason [string] (or enum): Standardized Windows shutdown reason code (e.g., PlannedMaintenance, UnplannedHardwareIssue, PlannedOperatingSystemReconfig) mapped to standard Windows Major:Minor reason codes.

Activity

  1. added
    Issue-Enhancementthe issue is more of a feature request than a bug
    Needs-TriageThe issue is new and needs to be triaged by a work group.
    on Oct 7, 2026
  2. soroshsabz commented on Oct 7, 2026

    @soroshsabz
    Author

    I can provide PR for this too

  3. soroshsabz commented on Oct 7, 2026

    @soroshsabz
    Author

    I think all of these features can be implemented cross-platform

  4. kilasuit commented on Oct 8, 2026

    @kilasuit
    Collaborator

    This PR is awaiting to be merged that will bring delay, reason & comment to both Stop-Computer & Restart-Computer cmdlets but is currently only targeting these cmdlets on Windows.

    I think all of these features can be implemented cross-platform

    I'm not sure that they can. Or at least it was determined previously that it made sense to manage the internals of these commands in separate files, Computer.cs (for the Windows implementations) & ComputerUnix.cs (for non-Windows) due to different features that are available across platforms. Like for example on Windows we can make use of Windows API's.

  5. soroshsabz commented on Oct 8, 2026

    @soroshsabz
    Author

    Ryan Yates (@kilasuit) Ok, so after merging PR #27721 we can submit another PR to add Linux support

  6. rhubarb-geek-nz commented on Oct 8, 2026

    @rhubarb-geek-nz

    add Linux support

    Given the existing implementation I am not expecting much.

    PS> Stop-Computer
    Stop-Computer: The term 'shutdown' is not recognized as a name of a cmdlet, function, script file, or executable program.
    Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    

    Good POSIX practice is to not run programs as root until you absolutely need to, then you use sudo or equivalent to run that single command. So yes, /usr/sbin/shutdown does exist but I would not recommend running PowerShell as root, it is a bull-in-a-china-shop in comparison to nimble bash.

    My recommendation would be that all cmdlets with nouns Computer or Service are removed from the codebase and relocated into separate repositories and hosted in PSGallery. There is no need for these cmdlets to share the same software-lifecycle of core PowerShell apart from for historical reasons.

    Or shutdown or sudo actually don't exist.

    alpine:~$ pwsh -version
    PowerShell 7.6.1-0-gfeb892adb53cb138a59f135d98a77c4bb2fbdba5
    alpine:~$ sudo su -
    -sh: sudo: not found
    alpine:~$ su -
    Password: 
    alpine:~# shutdown -h now
    -sh: shutdown: not found
    alpine:~# poweroff
    alpine:~# Connection to 192.168.64.13 closed by remote host.
    

    In Alpine's case we use 'poweroff'.

  7. 237dmitry commented on Oct 8, 2026

    @237dmitry

    So yes, /usr/sbin/shutdown does exist

    In systemd-based distributions, the /usr/bin/shutdown is a symbolic link to systemctl.

    shutdown --help:

    This is a compatibility interface, please use the more powerful 'systemctl
    halt', 'systemctl poweroff', 'systemctl reboot' commands instead.
    

    Additionally, it is necessary to check for the presence of sudo, systemd-run (run0), or doas and determine whether elevated privileges are required to execute the command. For example, on Arch, these are not needed for the reboot, poweroff, and systemctl suspend commands.

    There is no need for these cmdlets

    Exactly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugNeeds-TriageThe issue is new and needs to be triaged by a work group.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions