
Net framework library method in PowerShell to set an environment variable permanently for the user and machine for permanent use. After closing the PowerShell terminal, it doesn’t store the value. Use $Env:Path to set an environment variable for the current session only and process scope. I hope the above article to set an environment variable for a user and machine is helpful to you. Use dir env: to print the environment variable name and their path.

It will append value C:\go\bin to the environment variable Path and will be available for the current session only. Let’s consider an example to append a new value to the environment variable using $Env: Path as follows $Env:Path += "C:\go\bin\" To append a new value to an environment variable, use += and specify the variable value. uses EnvironmentVariableTarget as a user to set up an environment for user accounts only.Ĭool Tip: How to run PowerShell as a System account! Append new value to Environment Variable In the above PowerShell script, uses the SetEnvironmentVariable method to set an environment variable permanently for a user and its value will persist permanently. ::SetEnvironmentVariable('GoHugo','C:\Hugo\bin',::User) To create an environment variable permanently for a user account, use method to set an environment variable for a user. PS C:\> Use Powershell to Set Environment Variables for a user

+ CategoryInfo : ObjectNotFound: (GoHugo:String), ItemNotFoundException Get-ChildItem : Cannot find path 'GoHugo' because it does not exist. It will give an error message as the environment variable remains available for that process scope only.

Run the Get-ChildItem command again to get the environment variable created in the above step. PowerShell set environment variable for the sessionĬlose the PowerShell window and open it again.
