Update PowerShell telemetry to respect the diagnostics and feedback setting on Windows#27328
Update PowerShell telemetry to respect the diagnostics and feedback setting on Windows#27328daxian-dbw wants to merge 5 commits intoPowerShell:masterfrom
Conversation
…etting on Windows
There was a problem hiding this comment.
Pull request overview
Updates PowerShell’s telemetry initialization on Windows to respect the OS “Diagnostics & feedback” policy, and adds ETW plumbing to surface failures when reading that policy.
Changes:
- Add
WindowsDataCollectionSettingWinRT/COM interop helper to queryPlatformDiagnosticsAndUsageDataSettings. - Gate
ApplicationInsightsTelemetryinitialization based on Windows diagnostics collection level. - Add a new operational ETW event/task and update the ETW manifest/resources accordingly.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
There was a problem hiding this comment.
This fix is not related to the feature. I found it when reading the code. The requirement for balancing the call of CoInitializeEx is documented in https://learn.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-coinitializeex#remarks. I quote it below:
To uninitialize the COM library gracefully on a thread, each successful call to CoInitialize or CoInitializeEx, including any call that returns S_FALSE, must be balanced by a corresponding call to CoUninitialize.

PR Summary
Update PowerShell telemetry to respect the diagnostics and feedback setting on Windows.
WindowsDataCollectionSetting.csto handle calling the WinRT APIIPlatformDiagnosticsAndUsageDataSettingsStaticsfalseto disable the telemetryPowerShell.Core.Instrumentation.manto include the resources used in the new ETW event.PowerShellrepo and thePowerShell-Nativerepo, and actually, the one inPowerShell-Nativeis what we use to create the resource DLLPowerShell.Core.Instrumentation.dll.PowerShell.Core.Instrumentation.manfile to converge the changes in both placesPowerShell-NativerepoPR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header