Tuesday 4 December 2018

Set path environment variable via Powershell

The below code can be used to append path environment variable.

Param 
      (
                  [Parameter(Mandatory=$false)]
                  [System.String]
                  $pathtoAppend = "C:\Tools\java\bin"
        )
$env_Path = [Environment]::GetEnvironmentVariable("Path","Machine")
$finalPath = "$env_Path;$pathtoAppend"
[Environment]::SetEnvironmentVariable("Path",$finalPath ,"Machine")

In the similar way, you can set/Append any environment variables in windows.

No comments:

Post a Comment