Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can use 'set' to view envars. Want to see your postgres envars? Type 'set pg' and it will show anything starting with 'pg'.

You can use 'setx' to permanently set envars too.

You don't need to logout to use them, just restart cmd or whatever program you use.



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")


I 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 }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: