Skip to content

[release/v7.6.1] Add verbose message to Get-Service when properties cannot be returned#27250

Closed
daxian-dbw wants to merge 1 commit into
PowerShell:release/v7.6.1from
daxian-dbw:backport/release/v7.6.1/27109-30f70ee77
Closed

[release/v7.6.1] Add verbose message to Get-Service when properties cannot be returned#27250
daxian-dbw wants to merge 1 commit into
PowerShell:release/v7.6.1from
daxian-dbw:backport/release/v7.6.1/27109-30f70ee77

Conversation

@daxian-dbw
Copy link
Copy Markdown
Member

Backport of #27109 to release/v7.6.1

Triggered by @daxian-dbw on behalf of @reabr

Original CL Label: CL-General

/cc @PowerShell/powershell-maintainers

Impact

REQUIRED: Choose either Tooling Impact or Customer Impact (or both). At least one checkbox must be selected.

Tooling Impact

  • Required tooling change
  • Optional tooling change (include reasoning)

Customer Impact

  • Customer reported
  • Found internally

Fixes #24272 – adds verbose messages to Get-Service when service properties (Description, DelayedAutoStart, BinaryPathName, StartupType, UserName) cannot be retrieved due to permissions or other issues. Only visible when using -Verbose, so it is non-intrusive by default.

Regression

REQUIRED: Check exactly one box.

  • Yes
  • No

This is not a regression.

Testing

Verified locally that verbose messages appear for services with missing MUI resources (e.g. NPSMSvc, WaaSMedicSvc) when running Get-Service -Verbose. Backport applies cleanly with no conflicts.

Risk

REQUIRED: Check exactly one box.

  • High
  • Medium
  • Low

Only adds verbose output when -Verbose is explicitly used; standard Get-Service behavior is completely unchanged.

@daxian-dbw daxian-dbw added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Apr 10, 2026
Copilot AI review requested due to automatic review settings April 10, 2026 08:03
@daxian-dbw daxian-dbw closed this Apr 10, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Backport to release/v7.6.1 that adds a new verbose message for Get-Service when optional service properties cannot be retrieved (permissions, missing resources, etc.), without changing default output.

Changes:

  • Added a new localized resource string (CouldNotGetServiceProperty) for verbose messaging.
  • Updated GetServiceCommand to emit verbose messages when native service configuration queries fail.
  • Refactored AddProperties to be instance-based to allow calling WriteVerbose.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
src/Microsoft.PowerShell.Commands.Management/resources/ServiceResources.resx Adds the new verbose message resource string (plus some unrelated whitespace-only reformatting).
src/Microsoft.PowerShell.Commands.Management/commands/management/Service.cs Emits -Verbose messages when querying service description/delayed autostart/config fails.

Comment on lines +729 to +732
else
{
WriteServicePropertyError(service.ServiceName, nameof(NativeMethods.SERVICE_DESCRIPTIONW));
}
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

The verbose message currently uses nameof(NativeMethods.SERVICE_DESCRIPTIONW) as the “property” name, which will surface a native struct identifier (e.g., SERVICE_DESCRIPTIONW) rather than the user-facing PowerShell property (Description). Consider passing the actual PS property name so Get-Service -Verbose output is actionable.

Copilot uses AI. Check for mistakes.
}
else
{
WriteServicePropertyError(service.ServiceName, nameof(NativeMethods.SERVICE_DELAYED_AUTO_START_INFO));
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

Same issue here: using nameof(NativeMethods.SERVICE_DELAYED_AUTO_START_INFO) will emit a native type name in verbose output. Use the corresponding PowerShell property name (DelayedAutoStart) so the message matches what users see on the returned objects.

Suggested change
WriteServicePropertyError(service.ServiceName, nameof(NativeMethods.SERVICE_DELAYED_AUTO_START_INFO));
WriteServicePropertyError(service.ServiceName, "DelayedAutoStart");

Copilot uses AI. Check for mistakes.
}
else
{
WriteServicePropertyError(service.ServiceName, nameof(NativeMethods.QUERY_SERVICE_CONFIG));
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

nameof(NativeMethods.QUERY_SERVICE_CONFIG) will show the native struct name in the verbose message, but the failing retrieval affects multiple PS properties (BinaryPathName, UserName, StartupType). Consider emitting the relevant PowerShell property names (potentially one message per derived property) so users know what data is missing.

Suggested change
WriteServicePropertyError(service.ServiceName, nameof(NativeMethods.QUERY_SERVICE_CONFIG));
WriteServicePropertyError(service.ServiceName, "BinaryPathName");
WriteServicePropertyError(service.ServiceName, "UserName");
WriteServicePropertyError(service.ServiceName, "StartupType");

Copilot uses AI. Check for mistakes.
else
{
// handle when OpenServiceW itself fails:
WriteServicePropertyError(service.ServiceName, nameof(NativeMethods.SERVICE_QUERY_CONFIG));
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

On OpenServiceW failure, the “property” name is currently SERVICE_QUERY_CONFIG (an access right), which reads oddly in the verbose stream. Consider using a clearer label like OpenService/ServiceConfig or the affected PowerShell properties so the message communicates what could not be retrieved.

Suggested change
WriteServicePropertyError(service.ServiceName, nameof(NativeMethods.SERVICE_QUERY_CONFIG));
WriteServicePropertyError(service.ServiceName, "OpenService");

Copilot uses AI. Check for mistakes.
/// </summary>
/// <param name="serviceName">Name of the service.</param>
/// <param name="propertyName">Name of the property that failed to be queried.</param>
private void WriteServicePropertyError(string serviceName, string propertyName)
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

This helper writes to the verbose stream, but the name WriteServicePropertyError suggests it writes an error record. Renaming it to reflect the verbose-only behavior (e.g., WriteServicePropertyVerbose/WriteCouldNotGetServicePropertyVerbose) would reduce confusion for future maintainers.

Suggested change
private void WriteServicePropertyError(string serviceName, string propertyName)
private void WriteServicePropertyVerbose(string serviceName, string propertyName)

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +10
<!--
Microsoft ResX Schema
Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

This hunk reformats the ResX schema comment block (including adding trailing whitespace). Since it’s unrelated to the new resource entry, consider reverting these whitespace-only changes to avoid noisy diffs and potential style/whitespace lint issues in future merges.

Copilot uses AI. Check for mistakes.
@daxian-dbw daxian-dbw deleted the backport/release/v7.6.1/27109-30f70ee77 branch April 15, 2026 20:37
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.

3 participants