[WIP] Adding comment, Reason and RestartDelay parameter for Stop/Restart-Computer cmdlet#17479
[WIP] Adding comment, Reason and RestartDelay parameter for Stop/Restart-Computer cmdlet#17479kvprasoon wants to merge 1429 commits into
Conversation
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
| /// Specify a delay before the reboot occurs. | ||
| /// </summary> | ||
| [Parameter(ParameterSetName = DefaultParameterSet)] | ||
| [ValidateRange(0, UInt32.MaxValue)] |
There was a problem hiding this comment.
| [ValidateRange(0, UInt32.MaxValue)] | |
| [ValidateRange(ValidateRangeKind.Positive)] |
| flags[1] = Comment; | ||
| flags[2] = ShutdownReasons.Planned; | ||
|
|
||
| switch (Reason.ToString()) |
There was a problem hiding this comment.
Why can't we assign flags[2] = Reason?
| /// Provide a comment for rebooting the computer. | ||
| /// </summary> | ||
| [Parameter(ParameterSetName = DefaultParameterSet)] | ||
| public string Comment { get; set; } = string.Empty; |
There was a problem hiding this comment.
Why do we assign empty string? Can the parameter be null? If no we should add validation attribute.
There was a problem hiding this comment.
https://github.com/PowerShell/PowerShell/pull/8112/files#r228037418
It accepts null, will change to nullOrEmpty.
| /// <summary> | ||
| /// System related shutdown/restart. | ||
| /// </summary> | ||
| System = 0x80050000, |
There was a problem hiding this comment.
I have doubts that we should allow all these values. Perhaps the best options is the ones offered by WIndows GUI.
There was a problem hiding this comment.
was referring to previous discussions in the old PR
#8112 (comment)
Thought its an agreement to go ahead with the entire list.
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
PowerShell#26315) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com>
…owerShell#26322) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com>
…PowerShell#26268) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com> Co-authored-by: Travis Plunk <travis.plunk@microsoft.com>
Co-authored-by: Dongbo Wang <dongbow@microsoft.com> Co-authored-by: Travis Plunk <travis.plunk@microsoft.com>
…owerShell#26326) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com> Co-authored-by: Travis Plunk <travis.plunk@microsoft.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
The following experimental features are made stable: - PSNativeWindowsTildeExpansion - PSRedirectToVariable - PSSubsystemPluginModel
…owerShell#26355) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
… existing actions to use reusable get-changed-files action (PowerShell#26350) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com> Co-authored-by: Travis Plunk <travis.plunk@microsoft.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Travis Plunk (HE/HIM) <tplunk@ntdev.microsoft.com>
…PowerShell#26365) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com>
Co-authored-by: Aditya Patwardhan <adityap@microsoft.com>
…#27608) Co-authored-by: PowerShell Team Bot <69177312+pwshBot@users.noreply.github.com> Co-authored-by: Travis Plunk <travis.plunk@microsoft.com> Co-authored-by: Patrick Meinecke <SeeminglyScience@users.noreply.github.com>
Co-authored-by: Justin Chung <chungjustin@microsoft.com>
|
@kvprasoon are you still interested in finishing off this PR? |
Co-authored-by: Justin Chung <124807742+jshigetomi@users.noreply.github.com>
Co-authored-by: Ilya <darpa@yandex.ru>
|
Hey @kilasuit - I would like to. This was pending review from very long time. I will try to rebase and update the PR this week. |
There was a problem hiding this comment.
Pull request overview
This PR extends the Windows implementations of Stop-Computer and Restart-Computer to support -Comment, -Reason, and delay parameters (to align more closely with shutdown.exe behavior), and updates the WSMan CIM invocation to call Win32ShutdownTracker with the additional arguments.
Changes:
- Add
ShutdownReasonsenum plus new cmdlet parameters (Comment,Reason, and delay) toStop-Computer/Restart-Computer. - Switch WSMan shutdown invocation from
Win32ShutdowntoWin32ShutdownTrackerand passTimeout,Comment, andReasonCode. - Add Pester tests intended to validate parameter availability for
Stop-Computer/Restart-Computer.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 13 comments.
| File | Description |
|---|---|
| test/powershell/Modules/Microsoft.PowerShell.Management/Stop-Computer.Tests.ps1 | Adds tests for new -Comment and -Reason parameters. |
| test/powershell/Modules/Microsoft.PowerShell.Management/Restart-Computer.Tests.ps1 | Adds tests for new -Comment and -Reason parameters. |
| src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs | Adds new parameters/enums and updates WSMan shutdown invocation to use Win32ShutdownTracker. |
| $ReasonList = "Application", "Hardware", "OperatingSystem", "Other", "Power", "Software", "System", ` | ||
| "BlueScreen", "Disk", "Environment", "Driver", "HotFix", "HotFixUninstall", "Unresponsive", "Installation", ` | ||
| "Maintenance", "MMC", "NetworkConnectivity", "NetworkCard", "Other", "OtherDriver", "PowerSupply", "Processor", "Reconfigure", ` | ||
| "SecurityIssue", "SecurityPatch","SecurityPatchUninstallation", "ServicePack", "ServicePackUninstallation", "TerminalServices", ` | ||
| "Unstable", "Upgrade", "WMI" |
| It "Should support Reason types" { | ||
| $ReasonList = "Application", "Hardware", "OperatingSystem", "Other", "Power", "Software", "System", ` | ||
| "BlueScreen", "Disk", "Environment", "Driver", "HotFix", "HotFixUninstall", "Unresponsive", "Installation", ` | ||
| "Maintenance", "MMC", "NetworkConnectivity", "NetworkCard", "Other", "OtherDriver", "PowerSupply", "Processor", "Reconfigure", ` | ||
| "SecurityIssue", "SecurityPatch","SecurityPatchUninstallation", "ServicePack", "ServicePackUninstallation", "TerminalServices", ` | ||
| "Unstable", "Upgrade", "WMI" |
| // If successful and the Restart parameter is specified, restart the computer | ||
| object[] flags = new object[] { 6, 0 }; | ||
| ComputerWMIHelper.InvokeWin32ShutdownUsingWsman( | ||
| object[] flags = new object[] { 0, 0, 0, 6 }; | ||
| ComputerWMIHelper.InvokeWin32ShutdownTrackerUsingWsman( | ||
| this, |
| [Parameter] | ||
| [ValidateRange(ValidateRangeKind.Positive)] | ||
| public UInt32 ShutdownDelay { get; set; } |
| /// <summary> | ||
| /// Specify a delay before the reboot occurs. | ||
| /// </summary> |
| /// <summary> | ||
| /// Application related shutdown/restart. | ||
| /// </summary> | ||
| Application = 0x00040000, | ||
|
|
||
| /// <summary> | ||
| /// Hardware related shutdown/restart. | ||
| /// </summary> | ||
| Hardware = 0x80010000, |
| It "Should support -Comment parameter" { | ||
| Set-TesthookResult -testhookName $restartTesthookResultName -value $defaultResultValue | ||
| $comment = "Testing comment" | ||
| Stop-Computer -Comment $comment -ErrorAction Stop | Should -BeNullOrEmpty | ||
| } |
| It "Should support Reason types" { | ||
| $ReasonList = "Application", "Hardware", "OperatingSystem", "Other", "Power", "Software", "System", ` | ||
| "BlueScreen", "Disk", "Environment", "Driver", "HotFix", "HotFixUninstall", "Unresponsive", "Installation", ` | ||
| "Maintenance", "MMC", "NetworkConnectivity", "NetworkCard", "Other", "OtherDriver", "PowerSupply", "Processor", "Reconfigure", ` | ||
| "SecurityIssue", "SecurityPatch","SecurityPatchUninstallation", "ServicePack", "ServicePackUninstallation", "TerminalServices", ` | ||
| "Unstable", "Upgrade", "WMI" | ||
| foreach ( $reason in $ReasonList ) { | ||
| Stop-Computer Reason $reason | Should -BeNullOrEmpty | ||
| } | ||
| } |
| It "Should support -Comment parameter" { | ||
| Set-TesthookResult -testhookName $restartTesthookResultName -value $defaultResultValue | ||
| $comment = "Testing comment" | ||
| Restart-Computer -Comment $comment -ErrorAction Stop | Should -BeNullOrEmpty | ||
| } |
| It "Should support Reason types" { | ||
| $ReasonList = "Application", "Hardware", "OperatingSystem", "Other", "Power", "Software", "System", ` | ||
| "BlueScreen", "Disk", "Environment", "Driver", "HotFix", "HotFixUninstall", "Unresponsive", "Installation", ` | ||
| "Maintenance", "MMC", "NetworkConnectivity", "NetworkCard", "Other", "OtherDriver", "PowerSupply", "Processor", "Reconfigure", ` | ||
| "SecurityIssue", "SecurityPatch","SecurityPatchUninstallation", "ServicePack", "ServicePackUninstallation", "TerminalServices", ` | ||
| "Unstable", "Upgrade", "WMI" | ||
| foreach ( $reason in $ReasonList ) { | ||
| Restart-Computer -Reason $reason | Should -BeNullOrEmpty | ||
| } | ||
| } |
…rShell#26185) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Justin Chung <124807742+jshigetomi@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Justin Chung <124807742+jshigetomi@users.noreply.github.com>
…owerShell#27611) Co-authored-by: Justin Chung <chungjustin@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…ipeline (PowerShell#27667) 1. Create the `LocProject.json` file for PowerShell localization. 2. Remove the unused `.resx` resource files and source files. 3. Update the `ResourceValidation` tests.
Co-authored-by: Ilya <darpa@yandex.ru>
…shell into stopmessage-4857
PR Summary
Fixes: #4857
PR Context
This PR helps as it adds parameters which helps PowerShell users use Stop-Computer and Restart-Computer more like shutdown.exe.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).