Skip to content

Adding comments and reasons to Restart-Computer/Stop-Computer - #8112

Closed
Luke (lukepayne) wants to merge 1 commit into
PowerShell:masterfrom
lukepayne:computer-module-comments-reasons
Closed

Luke (lukepayne) wants to merge 1 commit into
PowerShell:masterfrom
lukepayne:computer-module-comments-reasons

Conversation

@lukepayne

@lukepayne Luke (lukepayne) commented Oct 24, 2018 •

Copy link
Copy Markdown

PR Summary

This change adds the ability to specify a comment as well as reason codes
for a reboot or shutdown of the computer. Also added is the option to
specify a timeout before the reboot/shutdown occurs.

fixes #4857

PR Checklist

This change adds the ability to specify a comment as well as reason codes
for a reboot or shutdown of the computer. Also added is the option to
specify a timeout before the reboot/shutdown occurs.

This issues is raised in issue no. 4857
@msftclas

Microsoft Contribution License Agreements (msftclas) commented Oct 24, 2018 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@vexx32

Copy link
Copy Markdown
Collaborator

Luke (@lukepayne) if you put something like "fixes #4857" in the PR description, then the issue will be closed when the maintainers merge the PR. Just saves them a few moments extra work 😉

private const uint TerminalServices = 0x00000020;
private const uint Unstable = 0x00000006;
private const uint Upgrade = 0x00000003;
private const uint WMI = 0x00000015;

@vexx32 Rain Sallow (/u/ta11ow) (vexx32) Oct 24, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are quite a few reason codes available which would indicate to me that this would be much better off as an enum for cleanliness and clarity; much easier for users to discover as well, if the parameter is typed with the enum type!

"Unstable",
"Upgrade",
"WMI")]
public string MinorReason { get; set; }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per my other comment, you can skip ValidateSet entirely and you could opt to either have two enums (one for major and one for minor reason) or you could opt to roll it all into a single enum and parameter, depending on which is appropriate.

If multiple codes can be specified, tag the enum(s) with the [Flags] attribute to permit this.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we should review the list. How we can call the cmdlet if "BlueScreen"?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to go for parity with what the Win32ShutdownTracker supports, but it makes sense to remove some of the illogical ones. Do you have suggestions on what should be removed?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd look options in Windows restart/shootdown dialog box.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The options from the Server shutdown dialog include the following options. It seems a bit restrictive given what the API supports.

image
image

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a bit restrictive given what the API supports.

because not all options make sense in interactive mode.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. So I would suggest not whittling it down to this list.

break;
case WaitForServiceTypes.PowerShell:
_powershell = System.Management.Automation.PowerShell.Create();
_powershell = global::System.Management.Automation.PowerShell.Create();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change necessary & what does it accomplish here? Never seen this sort of syntax in c# before, and I don't know if it's used anywhere else in the repo here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This forces the call to search in the global namespace, otherwise the 'System' prefix grabs the local System variable. However, this likely won't be an issue after the the reason codes are converted to enums.

private const uint TerminalServices = 0x00000020;
private const uint Unstable = 0x00000006;
private const uint Upgrade = 0x00000003;
private const uint WMI = 0x00000015;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above; it looks like you could roll most or all of these into a single enum that is shared between both commands.

/// <param name="cancelToken">Cancel token</param>
/// <returns>True on success</returns>
internal static bool InvokeWin32ShutdownUsingWsman(
internal static bool InvokeWin32ShutdownTrackerUsingWsman(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good idea to change the method name itself. If a new overload or a new method that does what you need is necessary, that's probably better, unless you're absolutely sure that nothing else calls this method at any point. It's flagged as internal, so potentially anything in the same namespace could call it, though I'm not sure if anything currently does.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no specific reason why it needs to be changed, it's just to match the name of the new CimOperatingSystemShutdownMethod. I can revert to the previous name as I don't think an overload is necessary.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. Yeah, if you can check the references to that method to see if anything else happened to also use it that would be best.

Otherwise I'll be more than happy to do a quick check in a bit just to make sure. 😆

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just did a quick check, and it doesn't look like anything else is using this method, so it's probably fine either way. 😄

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh great, thanks. I might leave it as is then to match the new shutdown method name 😀

@lukepayne

Copy link
Copy Markdown
Author

Luke (@lukepayne) if you put something like "fixes #4857" in the PR description, then the issue will be closed when the maintainers merge the PR. Just saves them a few moments extra work 😉

Thanks for the tip! I'll add that in :)

@iSazonov Ilya (iSazonov) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't duplicate code (dry principle) in both cmdlets.

@@ -173,6 +173,44 @@ public class RestartComputerCommand : PSCmdlet, IDisposable
private const string DefaultParameterSet = "DefaultSet";
private const int forcedReboot = 6; // see https://msdn.microsoft.com/library/aa394058(v=vs.85).aspx

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the link. (Now it is redirected).
And add doc link for new constants you are added below.

/// Provide a comment for rebooting the computer.
/// </summary>
[Parameter(ParameterSetName = DefaultParameterSet)]
public string Comment { get; set; } = "";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use string.Empty.

Style issue: all public comments for properties with { get; set; } should start with "Gets or sets"; (line 265)

"Power",
"Software",
"System")]
public string MajorReason { get; set; }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should enum too.

"Unstable",
"Upgrade",
"WMI")]
public string MinorReason { get; set; }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we should review the list. How we can call the cmdlet if "BlueScreen"?

_restartDelay = value;
}
}
private UInt32 _restartDelay = 0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove and use auto-property public UInt32 RestartDelay { get; set; }.
No need to init - default is 0.

_status = ComputerResources.RestartComplete;
WriteProgress(_indicator[indicatorIndex % 4] + _activity, _status, 100, ProgressRecordType.Completed);
_timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
_timer.Change(global::System.Threading.Timeout.Infinite, global::System.Threading.Timeout.Infinite);

@iSazonov Ilya (iSazonov) Oct 25, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Win32ShutdownTracker supports timeout so we could remove the code. /cc Steve Lee (@SteveL-MSFT)

@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Nov 16, 2018
@stale

stale Bot commented Dec 26, 2018

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days.
Thank you for your contributions.
Community members are welcome to grab these works.

@stale stale Bot added Stale and removed Stale labels Dec 26, 2018
@lukepayne

Copy link
Copy Markdown
Author

I'm hoping a comment is sufficient to keep this open for now. I intend to finish and commit once I'm back from holidays. Thanks!

@SteveL-MSFT

Copy link
Copy Markdown
Member

Luke (@lukepayne) even if stale-bot closes a PR, it's not deleted, so you can always come back and reactivate it. stale-bot just helps clean up some noise so people know which PRs are active and require attention.

@stale

stale Bot commented Feb 8, 2019

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days.
Thank you for your contributions.
Community members are welcome to grab these works.

@stale stale Bot added the Stale label Feb 8, 2019
@stale

stale Bot commented Feb 18, 2019

Copy link
Copy Markdown

This PR has been automatically closed because it is stale. If you wish to continue working on the PR, please first update the PR, then reopen it.
Thanks again for your contribution.
Community members are welcome to grab these works.

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

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restart-Computer and Stop-Computer should take custom message like shutdown.exe

5 participants