Title: [Environment]::SetEnvironmentVariable() fixes and improvements · Issue #26725 · PowerShell/PowerShell · GitHub
Open Graph Title: [Environment]::SetEnvironmentVariable() fixes and improvements · Issue #26725 · PowerShell/PowerShell
X Title: [Environment]::SetEnvironmentVariable() fixes and improvements · Issue #26725 · PowerShell/PowerShell
Description: Summary of the new feature / enhancement [Environment]::SetEnvironmentVariable("Variable", $null) should delete the environmentvariable and when passing [Environment]::SetEnvironmentVariable("Variable", "") it keeps the current behaviour...
Open Graph Description: Summary of the new feature / enhancement [Environment]::SetEnvironmentVariable("Variable", $null) should delete the environmentvariable and when passing [Environment]::SetEnvironmentVariable("Varia...
X Description: Summary of the new feature / enhancement [Environment]::SetEnvironmentVariable("Variable", $null) should delete the environmentvariable and when passing [Environment]::SetEnvironmentVaria...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/26725
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Environment]::SetEnvironmentVariable() fixes and improvements","articleBody":"### Summary of the new feature / enhancement\n\n1.\n[Environment]::SetEnvironmentVariable(\"Variable\", $null) \nshould delete the environmentvariable\n\nand when passing [Environment]::SetEnvironmentVariable(\"Variable\", \"\")\nit keeps the current behaviour of setting an empty variable\n\n2.\n[Environment]::GetEnvironmentVariable() add a new optional parameter that can be used to get a variable not expanded\nThis allows to save it to a variable and pass it directly to SetEnvironmentVariable without breaking %% inside variables\n\n3.\nalso for SetEnvironmentVariable it should detect if a % is inside the parameter and set the korrekt registrykey type when saving (reg_expand_sz) currently it always saves as reg_sz which breaks Path variable when used \n\n### Proposed technical implementation details (optional)\n\nhttps://stackoverflow.com/questions/69965728/cannot-remove-powershell-environment-variables\nhere the current behaviour is described.\n\nand for point 3 line 90 in file https://github.com/microsoft/PowerToys/blob/main/src/modules/EnvironmentVariables/EnvironmentVariablesUILib/Helpers/EnvironmentVariablesHelper.cs\n\n1.\nCan the powershell command be adjusted so that when passing\n[Environment]::SetEnvironmentVariable(\"Variable\", $null) \nit should pass [NullString]::Value\nand when passing [Environment]::SetEnvironmentVariable(\"Variable\", '')\nit keeps the current behaviour of empty.string\n\nthe current usage of\nusing [Environment]::SetEnvironmentVariable(\"Variable\", [NullString]::Value)\nis not very convinient or intuitive\n\n\n2.\ncurrently this is how we can get env variables\n[Environment]::GetEnvironmentVariable($Name, $Target)\n\nwe can expand this to be \n[Environment]::GetEnvironmentVariable($Name, $Target, $DoNotExpand)\n\nwhich toggles this behaviour\n\n3.\nIf the value passed to SetEnvironmentVariable($Name, $Value, $Target) contains \"%\" it should save as reg_expand_sz else reg_sz\n\nthis is already the implemented behaviour for EnvironmentVariable Editor inside PowerToys\nand writing the registry directly because of this issue with SetEnvironmentVariable and unable to get Env variable unexpanded with GetEnvironmentVariable","author":{"url":"https://github.com/AkitoTheGambler","@type":"Person","name":"AkitoTheGambler"},"datePublished":"2026-01-26T22:44:18Z","url":"https://github.com/PowerShell/PowerShell/issues/26725"}
| 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:d86f12ed-c17e-8608-56f0-1f54024519ca |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A7F6:9E9AB:3CC168:5347D4:6AFD31D6 |
| html-safe-nonce | 0220da671414e8aae8e36f71838f8c69671a787002f50bfda13246035b4c0c90 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBN0Y2OjlFOUFCOjNDQzE2ODo1MzQ3RDQ6NkFGRDMxRDYiLCJ2aXNpdG9yX2lkIjoiMjg2MTk0NDI2NTQxNDM1NzQ2MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f8d6253c260500b8b8ae411e52c4cffd219ee371b697c888d12acc8a0feda187 |
| hovercard-subject-tag | issue:3857994825 |
| 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/26725/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3b283ea61be514e9c90fed99a8716a2f15a88abbfdb681ac74f591957e0a11b6/PowerShell/PowerShell/issues/26725 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3b283ea61be514e9c90fed99a8716a2f15a88abbfdb681ac74f591957e0a11b6/PowerShell/PowerShell/issues/26725 |
| og:image:alt | Summary of the new feature / enhancement [Environment]::SetEnvironmentVariable("Variable", $null) should delete the environmentvariable and when passing [Environment]::SetEnvironmentVariable("Varia... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AkitoTheGambler |
| hostname | github.com |
| expected-hostname | github.com |
| None | 065128366c233a9d57ff68ab6c96e25b99dd1b0ab70d23b70873d3dd6b5e4f19 |
| 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 | 941021edf0c2ec58298f4a2c8f27ae507d129c92 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width