Skip to content

Fix checks for local user config file paths#26269

Merged
TravisEz13 merged 3 commits intoPowerShell:masterfrom
SeeminglyScience:fix-checks-for-user-configs
Oct 22, 2025
Merged

Fix checks for local user config file paths#26269
TravisEz13 merged 3 commits intoPowerShell:masterfrom
SeeminglyScience:fix-checks-for-user-configs

Conversation

@SeeminglyScience
Copy link
Copy Markdown
Contributor

PR Summary

With these changes, SYSTEM's default config path is C:\Windows\system32\config\systemprofile\Documents\PowerShell\powershell.config.json regardless of if the directory Documents exists.

If the location for Documents is configured in the OS to be an empty string (if that's even possible), user based config loading will be skipped entirely.

PR Context

  • Use the DoNotVerify option with Environment.GetFolderPath, ensuring the configured location will be returned regardless of if it has been created already
  • If we get an empty string, null or whitespace from GetFolderPath, consider that as disabled and skip loading or processing further for that location.

PR Checklist

- Use the `DoNotVerify` option with `Environment.GetFolderPath`,
  ensuring the configured location will be returned regardless of if it
  has been created already
- If we get an empty string, null or whitespace from `GetFolderPath`,
  consider that as disabled and skip loading or processing further for
  that location.
Copilot AI review requested due to automatic review settings October 21, 2025 21:00
@SeeminglyScience SeeminglyScience added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Oct 21, 2025
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

This PR fixes user config handling by ensuring PowerShell uses DoNotVerify option when retrieving special folder paths, preventing failures when directories don't exist yet. The main changes ensure that if a special folder path is empty or null, config loading is skipped for that location rather than failing.

Key Changes:

  • Added DoNotVerify option to Environment.GetFolderPath calls to return configured paths regardless of directory existence
  • Added null/empty checks to skip processing when special folder paths are unavailable
  • Introduced helper methods SafeDeriveFromSpecialFolder and TryDeriveFromCache to safely derive paths from special folders

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
CorePsPlatform.cs Added helper methods for safe path derivation and updated cache/config directory initialization to use DoNotVerify
PSConfiguration.cs Added null check before using per-user config file path
Telemetry.cs Updated to use cached UUID path and skip telemetry if path unavailable; moved environment variable parsing to private method
AnalysisCache.cs Updated to use TryDeriveFromCache and skip serialization if cache location unavailable
UpdatesNotification.cs Updated to use TryDeriveFromCache and disable notifications if cache unavailable
ConsoleHost.cs Added null check before using profile directory
CommandDiscovery.cs Updated user profile path retrieval to use DoNotVerify option
MshHostUserInterface.cs Added null/empty check for base directory in transcript path generation
HostUtilities.cs Fixed brace placement in conditional logic

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/System.Management.Automation/utils/Telemetry.cs Outdated
@SeeminglyScience SeeminglyScience changed the title Fix checks for user configs Fix checks for local user config file paths Oct 21, 2025
@TravisEz13 TravisEz13 self-assigned this Oct 21, 2025
@TravisEz13 TravisEz13 enabled auto-merge (squash) October 21, 2025 21:31
@TravisEz13 TravisEz13 merged commit c7ee0d2 into PowerShell:master Oct 22, 2025
41 of 43 checks passed
@microsoft-github-policy-service
Copy link
Copy Markdown
Contributor

microsoft-github-policy-service Bot commented Oct 22, 2025

📣 Hey @@SeeminglyScience, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

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

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants