Title: Support CMD-Style Environment Variable Expansion (%VARIABLE%) in PowerShell · Issue #28408 · PowerShell/PowerShell · GitHub
Open Graph Title: Support CMD-Style Environment Variable Expansion (%VARIABLE%) in PowerShell · Issue #28408 · PowerShell/PowerShell
X Title: Support CMD-Style Environment Variable Expansion (%VARIABLE%) in PowerShell · Issue #28408 · PowerShell/PowerShell
Description: Summary of the new feature / enhancement As a PowerShell user and Windows administrator, I would like PowerShell to support both its native $env:VARIABLE syntax and the traditional Windows Command Prompt %VARIABLE% syntax when referencin...
Open Graph Description: Summary of the new feature / enhancement As a PowerShell user and Windows administrator, I would like PowerShell to support both its native $env:VARIABLE syntax and the traditional Windows Command ...
X Description: Summary of the new feature / enhancement As a PowerShell user and Windows administrator, I would like PowerShell to support both its native $env:VARIABLE syntax and the traditional Windows Command ...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/28408
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support CMD-Style Environment Variable Expansion (%VARIABLE%) in PowerShell","articleBody":"### Summary of the new feature / enhancement\n\nAs a PowerShell user and Windows administrator, I would like PowerShell to support both its native `$env:VARIABLE` syntax and the traditional Windows Command Prompt `%VARIABLE%` syntax when referencing environment variables in commands and scripts.\n\nFor example, both of the following would resolve to the same environment variable value:\n\n```powershell\n$env:USERPROFILE\n%USERPROFILE%\n```\n\n**Reason for the request:**\n\nWindows documentation, administrative utilities, installation instructions, and configuration interfaces frequently reference environment variables using the traditional `%VARIABLE%` notation.\n\nFor example, Windows Defender Firewall supports environment variables such as `%windir%` when specifying application paths in firewall rules.\n\nHowever, when working in PowerShell, administrators must translate these references into PowerShell's `$env:VARIABLE` syntax or explicitly expand them using another method.\n\nSupporting both syntaxes would:\n\n- Improve consistency between PowerShell, Command Prompt, and Windows administrative interfaces.\n- Make it easier to copy and adapt commands and paths from existing Windows documentation.\n- Reduce the need to manually translate environment variable references.\n- Improve usability for administrators and learners transitioning from Command Prompt to PowerShell.\n- Allow existing Windows-style paths containing environment variables to be used more naturally in PowerShell commands and scripts.\n\nThe intent is not to replace PowerShell's existing environment variable syntax, but to provide additional compatibility and flexibility when working with Windows environment variables.\n\n### Proposed technical implementation details (optional)\n\nIdeally, PowerShell would recognize and expand `%VARIABLE%` references in addition to its existing `$env:VARIABLE` syntax.\n\nFor example:\n\n**Current PowerShell behavior:**\n\n```powershell\nWrite-Output $env:USERPROFILE\nGet-Item \"$env:WINDIR\\System32\"\n```\n\n**Proposed additional syntax:**\n\n```powershell\nWrite-Output %USERPROFILE%\nGet-Item \"%WINDIR%\\System32\"\n```\n\nBoth forms should produce equivalent results.\n\nThis capability could also support variable expansion within strings:\n\n```powershell\n$Path = \"%ProgramData%\\MyApplication\\Logs\"\n```\n\nPowerShell already provides similar functionality through .NET:\n\n```powershell\n[Environment]::ExpandEnvironmentVariables(\n '%ProgramData%\\MyApplication\\Logs'\n)\n```\n\nAdditionally, PowerShell currently recognizes `%VARIABLE%` references when using the `--%` stop-parsing token with native Windows commands.\n\nThe proposed enhancement would make this functionality more accessible within normal PowerShell usage, without requiring explicit .NET method calls or the stop-parsing token.\n\n**Compatibility considerations:**\n\nI recognize that introducing additional variable expansion syntax could affect existing scripts that intentionally use literal percent-delimited strings.\n\nPotential approaches could include:\n\n- Providing the functionality through an opt-in experimental feature or preference setting to preserve backward compatibility.\n- Following PowerShell's existing quoting conventions, where single-quoted strings remain literal.\n- Clearly defining behavior when a referenced environment variable does not exist.\n- Initially limiting the enhancement to Windows, where this notation is widely used.\n\nThe specific implementation should be determined by the PowerShell team, with an emphasis on maintaining backward compatibility while improving usability.\n\nThe primary objective is to allow administrators to use either environment variable notation naturally within PowerShell commands and scripts.","author":{"url":"https://github.com/darienhawkins","@type":"Person","name":"darienhawkins"},"datePublished":"2026-11-12T18:05:20Z","url":"https://github.com/PowerShell/PowerShell/issues/28408"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:55cc90ad-fd0d-e412-165b-bf3c46e9ad17 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BF76:3046F7:417645:565617:6AFCE972 |
| html-safe-nonce | 1a2cb92f99b7d2b2411ea8decc81bc902038da6322eb0504d5bd5c321a4520e1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRjc2OjMwNDZGNzo0MTc2NDU6NTY1NjE3OjZBRkNFOTcyIiwidmlzaXRvcl9pZCI6Ijc1NTM5NDg1MTIwMDg4NzE1NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9391df739a77b3ee90f37eb19c23944b1f5113988d31eb5966f040bf7a4ea1cf |
| hovercard-subject-tag | issue:6356020523 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/28408/issue_layout |
| twitter:image | https://opengraph.githubassets.com/70e38bfa08a8d971b7b8e93ce4b4c06686915d157c355686c8cba6e10a50ce61/PowerShell/PowerShell/issues/28408 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/70e38bfa08a8d971b7b8e93ce4b4c06686915d157c355686c8cba6e10a50ce61/PowerShell/PowerShell/issues/28408 |
| og:image:alt | Summary of the new feature / enhancement As a PowerShell user and Windows administrator, I would like PowerShell to support both its native $env:VARIABLE syntax and the traditional Windows Command ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | darienhawkins |
| hostname | github.com |
| expected-hostname | github.com |
| None | 99aede4c5f55ec5cf06666a8c9e03ebf9f85f7231223e7f1c38c16e5504835b3 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ecfd63ca125ec74b42f74eeb158b3fa081c8c497 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width