[release/v7.5.7] Update PowerShell telemetry to respect the diagnostics and feedback setting on Windows#27472
Open
adityapatwardhan wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Backport to release/v7.5.7 that gates PowerShell telemetry on Windows based on the OS “Diagnostics & feedback” data-collection policy, using a WinRT API wrapper and emitting an ETW operational error event when the policy query fails.
Changes:
- Add a WinRT/COM interop wrapper (
WindowsDataCollectionSetting) to query Windows diagnostic data-collection permission and use it during telemetry initialization. - Add a new ETW operational error event/task for failures querying the Windows setting, and update the instrumentation manifest/resources accordingly.
- Update telemetry Pester tests to avoid running in environments where OS telemetry policy disables PowerShell telemetry.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/powershell/engine/Basic/Telemetry.Tests.ps1 | Adds OS telemetry-level detection and attempts to skip telemetry tests when OS policy disables telemetry. |
| src/System.Management.Automation/utils/WindowsDataCollectionSetting.cs | Adds WinRT activation factory interop to check Windows diagnostics/data-collection policy and logs ETW on failure. |
| src/System.Management.Automation/utils/Telemetry.cs | Gates telemetry on Windows via WindowsDataCollectionSetting and adjusts cache-path usage. |
| src/System.Management.Automation/engine/remoting/common/PSETWTracer.cs | Adds new PSEventId and PSTask for telemetry-setting failures. |
| src/System.Management.Automation/CoreCLR/CorePsPlatform.cs | Fixes COM initialization balancing comment/logic for STA support detection. |
| src/PowerShell.Core.Instrumentation/PowerShell.Core.Instrumentation.man | Adds ETW event/task/template/resource strings for the new telemetry-setting error event (plus related manifest convergence). |
Comment on lines
39
to
+54
| Describe "Telemetry for shell startup" -Tag CI { | ||
| BeforeAll { | ||
| $skipTelemetryTests = $false | ||
|
|
||
| if ($IsWindows) { | ||
| ## Skip telemetry tests if the OS telemetry level is less than 2 (Enhanced) -- PS telemetry is disabled in this case. | ||
| $osTelemetryLevel = Get-OSTelemetryLevel | ||
| $skipTelemetryTests = $osTelemetryLevel -lt 2 | ||
| } | ||
|
|
||
| if ($skipTelemetryTests) { | ||
| $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() | ||
| $PSDefaultParameterValues["it:skip"] = $true | ||
| return | ||
| } | ||
|
|
Comment on lines
+19
to
+33
| # 1. Check the "Managed" Policy (Group Policy) | ||
| if (Test-Path $gpoPath) { | ||
| $gpoValue = Get-ItemProperty -Path $gpoPath -Name $valueName -ErrorAction SilentlyContinue | ||
| if ($gpoValue -and $gpoValue.$valueName) { | ||
| return [int]$gpoValue.$valueName | ||
| } | ||
| } | ||
|
|
||
| # 2. Check the "User/System" Preference (Settings App) | ||
| if (Test-Path $sysPath) { | ||
| $sysValue = Get-ItemProperty -Path $sysPath -Name $valueName -ErrorAction SilentlyContinue | ||
| if ($sysValue -and $sysValue.$valueName) { | ||
| return [int]$sysValue.$valueName | ||
| } | ||
| } |
daxian-dbw
requested changes
May 18, 2026
3c4da0d to
291d422
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #27328 to release/v7.5.7
Triggered by @adityapatwardhan on behalf of @daxian-dbw
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
Customer Impact
This change ensures telemetry honors the Windows diagnostics and feedback setting and avoids sending telemetry when disabled.
Regression
REQUIRED: Check exactly one box.
This is not a regression.
Testing
Validated by cherry-pick resolution, existing telemetry tests updated in the commit, and build/runtime behavior remains gated by telemetry enablement checks.
Risk
REQUIRED: Check exactly one box.
The change is limited to telemetry initialization gating and ETW logging paths, with no impact on core command execution.
Merge Conflicts
Resolved conflict in src/System.Management.Automation/utils/Telemetry.cs by taking the PR version and preserving release branch compatibility.