3 ms·
Or you can just use PowerShell, which allows you to manipulate all kinds of things in a filesystem-like manner (PSProviders): Get-ChildItem env: New-Item -Pat
by noinsight 11y ago
Or you can just use PowerShell, which allows you to manipulate all kinds of things in a filesystem-like manner (PSProviders):
Get-ChildItem env:
New-Item -Path "env:\myvar" -Value "MyValue"
Amongst other things, it works for the registry and even Active Directory.
Edit: for persistency you actually need to use [Environment]::SetEnvironmentVariable("TestVariable", "Test value.", "User")
- ygra 11y agoI answered an interesting SO question on that recently, which asked how to save and restore the environment in PowerShell. Turns out, the environment being in a PSDrive helps very much with that because you can treat the variables just like you treat files: # Save environment $savedState = Get-ChildItem Env: # Restore environment Remove-Item Env:* $savedState | ForEach-Object { Set-Content Env:$($_.Name) $_.Value }