Skip to content

Add some shutdown.exe functionality into Restart-Computer/Stop-Computer #12106

Closed

Description

Summary of the new feature/enhancement

Over the last year or two, shutdown.exe has gained several new and worthwhile options (/g, /sg, /fw, etc.) which aren’t present in restart-computer. I would like to see these implemented in Restart-Computer (especially the three I mentioned).

The /g option (reboot with auto-restart) makes reboots easier. The /sg option (shutdown with auto-restart) makes shutdowns followed by restarts easier. The /fw option (reboot to firmware) solves the age-old problem of "which special key do I hit to get to BIOS/UEFI???"

Proposed technical implementation details (optional)

I don't know how the new options are implemented. I presume some Win32 call.

But for PowerShell, some new parameters such as [-Reboot] [-AutoRestart] [-Shutdown] [-Firmware] in appropriate parametersets would be desirable.

Oops.... TIL about Stop-Computer. I didn't even realize Stop-Computer existed until I was reading about #4857 (which leads to the question, what happened to #8112)?

So I guess I'm actually asking for [-AutoRestart] and [-Firmware] to be implemented in both Restart-Computer and Stop-Computer.

Activity

  1. added
    Issue-Enhancement
    on Mar 11, 2020
  2. added
    Issue-Question
    and removed
    Issue-Enhancement
    on Mar 12, 2020
  3. essentialexch commented on Mar 12, 2020

    @essentialexch
    Author

    Far be it from me to claim to be a programmer (I'm not, I'm just an admin scripter).

    But according to Win32ShutdownTracker, it's implemented using ExitWindowsEx():

    PS C:\scripts> get-cimclass -class win32_operatingsystem | 
        select -expand cimclassmethods |? { $_.Name -eq 'Win32ShutdownTracker' } |
        select -expand qualifiers |? { $_.Name -eq 'mappingstrings' } | 
        select Value
    
    Value
    -----
    {Win32API|System Shutdown Functions|ExitWindowsEx}
    

    AutoRestart (and Reboot and Shutdown) is fully defined within ExitWindowsEx(). I would guess the Win32ShutdownTracker doc was not updated with EWX_RESTARTAPPS.

    Insofar as how reboot to BIOS/UEFI is done - I'm not sure. I would expect it to be another parameter to ExitWindowsEx() (there are 3 others defined in WinUser.h: EWX_QUICKRESOLVE, EWX_HYBRID_SHUTDOWN, and EWX_BOOTOPTIONS but these are not explicitly documented). EWX_BOOTOPTIONS seems likely.

    Since both shutdown.exe and the Windows 10 UI know how to do a "reboot to BIOS/UEFI", it can't be too much of a secret (UI: Start --> Settings --> Update & Security --> Recovery --> Advanced Startup).

    I can experiment with those 3 options.

  4. TravisEz13 commented on Mar 12, 2020

    @TravisEz13
    Member

    It's also entirely possible that the option, is not a public API.

  5. essentialexch commented on Mar 16, 2020

    @essentialexch
    Author

    ExitWindowsEx() works just fine and exposes all of the expected restart options shown by MSDN.

    With a P/Invoke/Add-Type I was able to do everything:

    $Win32 = Add-Type -Name 'Win32' `
        -Namespace 'Win32' `
        -MemberDefinition @" 
            [DllImport( "user32.dll" )] 
            public static extern int ExitWindowsEx( int uFlags, int dwReason ); 
    "@ -PassThru 
    
    

    It appears that WindowsShutdown() and WindowsShutdownTracker() mask and suppress several of the ExitWindowsEx() options. I don't know why - but I bet there are comments in the Win32 sources.

    But not that anything is a non-public API using ExitWindowsEx instead of ShutdownWindows*.

  6. iSazonov commented on Mar 16, 2020

    @iSazonov
    Collaborator

    I was able to do everything

    I don't see an option for -Firmware. Please update the issue description for latest status.

  7. added
    Up-for-Grabs
    on May 8, 2020
  8. TobiasPSP commented on Oct 27, 2021

    @TobiasPSP
    Collaborator

    This seems like a duplicate to #14222 so I am reiterating our conclusion and close this issue for now:

    After thorough debate, the cmdlet WG concluded:
    A platform-specific feature for which a native command exists generally is easily accessible from within PowerShell as-is. For example, it is trivial on a Windows system to use shutdown.exe in a PowerShell script.
    Using native commands may not be easily discoverable, though: the PowerShell help system wouldn't suggest this native command or provide help. This part could indeed be solved by adding the functionality to a core cmdlet.
    On the down side, this would decrease consistency and user experience on non-targeted systems though.
    So for platform specific features, the cmdlet WG recommends to continue to directly use appropriate native commands provided by the particular platform on the platforms where it is available. If additional PowerShell-specific functionality like risk mitigation (-whatif) etc is needed - native commands can easily be wrapped inside a PowerShell function.
    For these reasons, the issue was closed, and we hope our reasoning resonates with the community.

  9. doctordns commented on Jun 1, 2022

    @doctordns
    Collaborator

    The Cmdlet working group has looked at this issue. We are marking this as won't fix for the same reasons we outlined in a similar issue, #12106. The Working Group recognizes the value and need for cmdlets, but that doesn't preclude someone from running the native shutdown.exe command. If someone wants the benefits of a cmdlet, that is where the Crescendo module becomes important.

  10. 11 remaining items

  11. Jibun-no-Kage commented on Jun 25, 2022

    @Jibun-no-Kage

    I did not insult the team, I insulted the mind-set. This is a mind-set that is across the industry of software development in total, frankly. One example the gaming world, where before digital release, you had to get the code stable... and right. Because deployment was expensive to recall, on physical media. But the actual, second, so to speak, it was easy to publish updates, there was direct and explicit decline in the quality of the code development and greater push to release less than solid code... after all as one developer said, 'hey we can just deploy a fix easy now, right?' That is so wrong, that if you can't see that point, you miss one of the key issues I am stressing.

    The other issue is parity of design. Not designing well, with strong parity and thought of how and why you make such decisions, you are not doing yourself or you end-user population any favors. The Restart-Computer/Stop-Computer is just an easy example that illustrates, that yes, someone cut a corner, and someone did not call it out. To your point, how it important is? Look at all the examples on Google about work-arounds... if that does not tell you something was wrong with the cmdlets, what can I say to convince you of my point about parity of design? Scripting exists to save time and effort, versus traditional coding methods such as C or Pascal, which saved time and effect in their own right, otherwise we would all still be coding in Macro Assembler.

    To be fair, I am not expecting anything to change per se. It maybe, likely that Restart-Computer/Stop-Computer just fade away and disappear over time. There are better ways to do the same thing across each part of the total eco-system, and as others have suggested, time better spent after other goals for PowerShell. But the lesson to be learned, IMHO, is if you tackle something in PowerShell that already exists elsewhere.... Do it right, met feature set parity, or improve it, but don't remove a key feature because it is hard to do, might take more time, or some other explanation that removes parity. Your end-users hate these blind-corners, snafus. I know this after years of serious development, being a QA/QC lead, as well as early virtualization adopter. If you are going to do something to it right. Anyone that looks at Restart-Computer/Stop-Computer, knows it just screams, as an example, of not being done right.

  12. jhoneill commented on Jun 25, 2022

    @jhoneill

    I did not insult the team, I insulted the mind-set.

    If you insult a way of thinking, the people who think that way are going to feel insulted.

    The other issue is parity of design.

    Not really. When PowerShell 1 released and Windows Vista / Server 2008 was the current OS, there was parity of design. There isn't a PM for Stop-Computer and Restart-Computer so as functionality is added to shutdown.exe there is no automatic way for the cmdlet to grow.

    With PowerShell 6 and 7 the PowerShell team are focused on the engine more than on the Windows-specific commands. But as an Open Source project people are free to put forward enhancements .

    This in the first post

    So I guess I'm actually asking for [-AutoRestart] and [-Firmware] to be implemented in both Restart-Computer and Stop-Computer.

    Is a start. If there should be others Jibun-no-Kage you're welcome to propose them (though have a read of https://smile.amazon.co.uk/How-win-friends-Influence-People-ebook/dp/B09ST4JLBQ/ref=sr_1_1?keywords=how+to+win+friends+and+influence+people&qid=1656189952&sprefix=how+to+%2Caps%2C89&sr=8- first)

    I see no reason why that shouldn't be flagged as "up for grabs". It wouldn't be harmful, and has some benefit, and doesn't need to be written by the core team. It doesn't look like very difficult C# to write so if someone from the community wants to do it, great, if not it shows it's not good use of Microsoft people's time.

  13. Jibun-no-Kage commented on Jun 25, 2022

    @Jibun-no-Kage

    James O'Neill (@jhoneill). really, recommending a book? One I have read by the way, years ago. But that is not relevant to the question posed. Frankly, people need to stop worrying about their feelings, and focus on quality code, and good design. When that is done, the result is benefit to everyone. Call it a suggestion, to your suggestion that some one may pick up the task as you offered.

  14. essentialexch commented on Jun 25, 2022

    @essentialexch
    Author

    It doesn't look like very difficult C# to write so if someone from the community wants to do it, great, if not it shows it's not good use of Microsoft people's time.

    It most certainly does not show that.

    The people that would benefit are those who are admin scripters. They are not the people who can write C#. They are the people that want to use PS to get a job done.

    A suggestion is for the OP to build a proxy Restart-Computer command that implements additional parameters.

    There y'all go again - suggesting that a scripter become a developer.

    You are forgetting a primary audience for PS, if not THE primary audience.

  15. Jibun-no-Kage commented on Jun 25, 2022

    @Jibun-no-Kage

    Michael B. (@essentialexch) Yes, that is an excellent point, very well said.

  16. jhoneill commented on Jun 26, 2022

    @jhoneill

    James O'Neill (@jhoneill). really, recommending a book? One I have read by the way, years ago. But that is not relevant to the question posed. Frankly, people need to stop worrying about their feelings, and focus on quality code, and good design. When that is done, the result is benefit to everyone. Call it a suggestion, to your suggestion that some one may pick up the task as you offered.

    Perhaps my point was too subtle. There is a famous book called "How to win friends and influence people", you're doing the opposite, being insulting just means no one wants to listen to you. It doesn't matter if you're right

    There is a piece of bug free code (so there is no quality issue), and which was designed 15 years ago and there was nothing wrong with the design at that time. Throwing insults around because the team has not made it a priority to go back and look at V1 cmdlets and see if they need to be updated won't make them re-order their priorities in the way that you want. Other contributors who might implement features will put their time into something else. "People need to stop worrying about their feelings" translates to people need to treat requests from those who insult them in the same way as people who are nice, and I wish you luck getting that to happen.

    It doesn't look like very difficult C# to write so if someone from the community wants to do it, great, if not it shows it's not good use of Microsoft people's time.

    It most certainly does not show that.

    The people that would benefit are those who are admin scripters. They are not the people who can write C#. They are the people that want to use PS to get a job done.

    The people who write these sort of things aren't, usually, writing just for themselves. There are community contributors with the C# skills who will write things they see a need for. If they could do it but think it would be bad use of their time why would it be good use of the Microsoft team's time?

    A suggestion is for the OP to build a proxy Restart-Computer command that implements additional parameters.

    There y'all go again - suggesting that a scripter become a developer.

    Since you were the OP, looking at what you've posted you're more than capable of generating a proxy function and adding an extra switch and a line IF ($switch) { shutdown.exe /xyz; return}

    There is no logoff command in PowerShell, and stop-computer does provide a choice between stop at the "safe to Power off" and "power the machine off" and so on. I'm not convinced that a Stop-UserSesssion command is better than logoff, or that "Restart-Computer -Firmware" is better than shutdown /fw Something like booting to the firmware menu is an interactive thing we do rarely and there may be reasons for not open-sourcing "re-start from the same place"
    there is nothing wrong with using shutdown.exe , or ping, or clip or format.

  17. Jibun-no-Kage commented on Jun 26, 2022

    @Jibun-no-Kage

    About the book.... clearly you don't understand, I don't care about being all goody goody nice. I made my point, and it factual and accurate. You would rather argue about something that is not relevant to the points made by me and others. Stop thinking about being a developer, and consider the needs of your end-user population.

  18. doctordns commented on Jun 27, 2022

    @doctordns
    Collaborator

    It feels to me that while youn may have a purist point, it is not all that helpful here. Yes, I agree - having better parity between shudowhn.exe and shutdown-computer would be nice. But today, it doesn't. So what do we do?

    Personally, I've never seen significant community input saying this change is needed. Most of the folks posting (eg in the Spiceworks PowerShell forum) seem content with the current cmdlet or the WIn32 console application as a workaround. I have written 5 books on PowerShell (the 5th is due out this autumn) and have managed just fine without this fix. What this says to me is that, while not perfect, this is a good enough solution. So where is this user population demanding this change? I just do not see it but could be looking in the wrong places

    And finally, why not create a module with a proxy function to demonstrate just what you are doing. Stick this into the PS gallery (and promote it!) then come back when you have loads of downloads. This might be another way to demonstrate the value of this change by allowing reconsideration based on facts, not personal biases.

    I have put this item on the agenda for the next cmdlet working group meeting. That said, I see no great reason NOT to close this issue as something we will not implement. But we can discuss. In the mean time, both suggestions above would help us to come to a conclusion.

  19. jhoneill commented on Jun 27, 2022

    @jhoneill

    Jibun-no-Kage
    I'm not a developer. I've spent 34 years working with IT pros / as an IT pro. I was a consultant and then an evangelist working at Microsoft for 10 years, so I have some grasp of how Microsoft worked - although people will tell me that particular Leopard has changed its spots. It has been by job to act as customer advocate and get the people who develop the product as customers need it which is not always the work they want to do. And I now sit on the cmdlet working group because I've written a ton of PowerShell (and a tiny amount of C#) over the last 15 years, and people seem to think I know what I'm talking about.
    I'm not always the politest person, and do tend to take a view that facts are facts, and if they only support one conclusion then that conclusion is right however it is presented. And the bitter fruit of 34 years experience is thinking that way has neither helped my career nor the customers I was acting as advocate for. Choosing to - as you put it - "care about being all goody goody nice" gets results more of the time.

    The position is:

    • There is far more work that the PowerShell team in Microsoft could do than Microsoft will assign developer/tester hours to do. So work must be prioritized
    • Now that PowerShell is open-source the team effort is augmented by the community, assuming that community members see it as worth their time. Where the Microsoft team is a single queue to fight for a place in, each community developer is another chance to get some developer hours, but only if they can be persuaded it is worth their time.
    • If anybody can do it but nobody comes forward to do then it shows a Microsoft decision not to do it was probably the right one - the team is there to do the jobs others can't, not as resource for the ones they don't want to do.
    • Assigning resources to features and enhancements uses a very fuzzy cost-benefit analysis. How many hours of effort does the work need, for how much benefit to how many people? What new scenarios are enabled ? What existing scenarios are improved, does anything work less well?
    • This is not a request to enable new scenarios - everything is already done by an external command that can be called from a script. Is a common scenario better with a PowerShell native command ? Being able to pipe a list of computers into restart or stop is a benefit , but reboot to firmware menu seems like a single computer task, done rarely, so if we do as you say "consider the needs of your end-user population." do they need this ? No, they don't. Some of them would like it, and a few scripts would be slightly more elegant. Do they have needs where effort would be better spent? Yes, many of them.
    • So this may get marked as "up for grabs", but I can't see Microsoft resource being devoted to it.
  20. TobiasPSP commented on Jun 27, 2022

    @TobiasPSP
    Collaborator

    James O'Neill (@jhoneill) thank you for this comprehensive summary. This reflects exactly what I feel. Thomas Lee (@doctordns) : technically this issue is closed already, we responded to post-close comments. Jibun-no-Kage: I hear you, and consistency and discoverability are great assets however PowerShell is serving a much wider audience in 2022 than in 2006, and is no longer a scripting language primarily targeted towards the Windows Admin. Instead, there are plenty of communities which each use vendor- and community-owned modules to make themselves at home. In the WG we are already discussing how community-driven modules can be made more readily available. In a perfect world, the mentioned suggestion could then be proposed not just to MSFT but possibly also to specific community-maintained module(s).

  21. essentialexch commented on Jun 27, 2022

    @essentialexch
    Author

    Modules and proxy functions are something that developers use. Not admin scripters.

    I've been writing PowerShell since it was called Monad and released in beta for E12. I've written two Exchange books of my own and tech edited more Exchange and AD books than I can remember. Plus exam authoring. Plus conferences. Yadda yadda yadda. My list of experience in IT matches or surpasses both of yours. Your attempted one-upmanship fails on me. And it really doesn't matter.

    In my 15+ years of PS usage I've written fewer than a handful of modules and zero proxy functions. I'm not a developer. I'm an admin scripter.

    My perspective as a user is just as valid as yours.

    One further comment and then I'm out:

    The people that would benefit are those who are admin scripters. They are not the people who can write C#. They are the people that want to use PS to get a job done.

    The people who write these sort of things aren't, usually, writing just for themselves. There are community contributors with the C# skills who will write things they see a need for.

    I don't think so. They are writing things that they are interested in. Big difference. As a 13-year MVP I'm well aware of how community contributions work.

  22. jhoneill commented on Jun 27, 2022

    @jhoneill

    Michael B. (@essentialexch) Sorry you feel that way. I played the 34 years in IT card because I didn't want to address another poster in terms which might look rude. I've failed doing things his way, and succeeded when I've been more... emollient.

    And yes Thomas Lee (@doctordns) Dr. Tobias Weltner (@TobiasPSP) and can I talk about our years doing this, the books we've written (yes I have my name on a some covers too - and I was an item writer for the Windows 2000 exams before I joined Microsoft), and Conferences we've spoken at - Tobias and I are just returned from PSConfEU And we'll all bang heads until we have the sense to stop. But actually "I know perfectly well who you are, and my perspective still is valid" is a very good reminder. Some issues that are opened are idiotic, this is not. It's something that would be done if we were starting today, and would be done today if we were not resource constrained. But from the position that we're in the benefits of reworking the cmdlet are small and it just won't meet the threshold for getting PowerShell team hours.

    I'm not sure you get what a proxy function is - it is just a function with the same name as a cmdlet which gets called first by normal rules of precedence, does something the cmdlet doesn't and then calls the fully-qualified cmdlet to do the rest - a simple way to extend functions. On the one hand you posted something using PInvoke, which I class as being developer stuff - with some big modules and proxy functions to my name I don't have anywhere in my own code so I took you to be more of a developer than I am - and on the other you talk your abilities down with "I'm just an admin scripter". I think you may be under-estimating yourself. But if it's too far outside your comfort zone then someone else needs to be persuaded to take the work on - which is where I came in.

  23. Jibun-no-Kage commented on Jun 27, 2022

    @Jibun-no-Kage

    Thomas Lee (@doctordns), of course now, revisiting the cmdlets of note, is unrealistic, by core PS development team. If you read my previous comments, I never asked for re-development, only that what development was done at the time, was not great, or not maintained well to maintain parity. These cmdlets are illustrative, of an issue that it should not be ignored, that a corner was cut, which I think was a bad decision, and at the risk of more book suggestions, pretty short sighted if not dumb. This is, if nothing else is a learning opportunity, of how not to cut a corner going forward.

    James O'Neill (@jhoneill) , So, you are the one that gave me nightmares?! I refer to the Windows 2000 exams. The exams were no joke back in the day, when I took them. :) The odd thing was, after I completed Novell CNE certification, moved to Microsoft certification, only after I moved to Microsoft, I moved deep into virtualization, beta testing the original VMware 'ESX' server for a Fortune 10 that was a very early adopter of each type of virtualization in 2001 no less. Oh, note I said 'ESX' not the later 'ESXi' solution, that should date me. LOL... only to circle back to Hyper-V and then get very deep into KVM, which led to precursor LXC containers, then Docker. But I digress.

    Dr. Tobias Weltner (@TobiasPSP), I agree with you, in reference to the future direction of PS, I think PS should only tackle the specific and narrow focus that eco-system requires, meaning that what is developed is done very well with due consideration of the end-users use cases and needs, save scripters time and effort, please repeat 1000s times. PS only exists to save time and effort, of scripters, IMHO. I will re-affirm one of my past points... if you decide to include something in PS of today, do it right, consider parity as a key goal across the eco-system. If you can't achieve extensive parity across the eco-system, and comparable for applicable existing options in each given OS, don't create a blind corner for scripters. The question then is, is the specific candidate really worth the effort? In that qualified mind-set, I doubt Restart-Computer/Stop-Computer would have ever been added to PS of the past, as an example.

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

Metadata

Metadata

Labels

Issue-QuestionResolution-DuplicateResolution-Won't FixWG-Cmdlets

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions