PowerShell FAQ
  • Initial page
  • PowerShell Frequently Asked Questions
    • getting-started
      • How do I determine the location of the current PowerShell script?
      • How do I set the PATH in PowerShell?
      • How do I determine the current version of PowerShell?
      • How do I pass parameters to PowerShell scripts?
      • How do I fix "the execution of scripts is disabled on this system" errors?
    • learning-paths
      • Are there any free PowerShell ebooks?
      • Is there any free training for PowerShell
      • books-for-programmers
      • video-resources
      • books-for-newbies
    • frequently-asked-faq-questions
      • contributing
      • What's the license for this FAQ?
    • SUMMARY
    • justification
      • Why should I learn PowerShell?
Powered by GitBook
On this page

Was this helpful?

  1. PowerShell Frequently Asked Questions
  2. getting-started

How do I set the PATH in PowerShell?

The PATH, like all environment variables, is accessible in PowerShell via the Env drive, and you can set it using variable syntax, like: $Env:PATH += ";$pwd" to add the present working directory to it. In Windows, the directory separator for the path is ";", but on Linux it's ":" -- to be safe, you can use [IO.Path]::PathSeparator like this: $Env:Path += [IO.Path]::PathSeparator + $pwd

Note that += is the "append" operator for strings.

To make changes permanent you can either put them in a profile script (which is cross-platform), or if you need the changes to affect apps outside PowerShell on Windows, you can force them into the environment storage using [Environment]::SetEnvironmentVariable -- but you must be careful, in this case, not to put your personal environment into the machine's environment. Here's a simple two-line script that will add a path to the PATH environment variable for all users in Windows:

function Add-Path($Path) {
    $Path = [Environment]::GetEnvironmentVariable("PATH", "Machine") + [IO.Path]::PathSeparator + $Path
    [Environment]::SetEnvironmentVariable( "Path", $Path, "Machine" )
}
PreviousHow do I determine the location of the current PowerShell script?NextHow do I determine the current version of PowerShell?

Last updated 4 years ago

Was this helpful?