Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

PowerShell – Create System Path

Posted on March 4, 2016March 4, 2016 By David Kittell

Possibly the easiest manual way is in Windows 10 and Windows 2012 R2 (likely previous versions too but don’t have them handy while writing this):

  1. From the Desktop, right click on the Windows icon (Start Menu) in the bottom left of the screen
  2. Click on “System”
  3. Click the “Advanced system settings” link in the left column.
  4. In the “System Properties” window, click on the “Advanced” tab, then click the “Environment Variables” button near the bottom of that tab.
  5. In the “Environment Variables” window, highlight the “Path” variable in the “System variables” section and click the Edit button. Add or modify the path lines with the paths you want the computer to access. Each different directory is separated with a semicolon”
  6. When done adding paths click the “OK” button on the “Edit System Variable” windows, the “OK” button on the “Environment Variables” window, the “OK” button on “System Properties” and close the “System” window.

This automated way is a little quicker, as with other code on my site make sure you understand what it’s doing before you do it on a production server.

function AddSystemPaths([array] $PathsToAdd) {

  $VerifiedPathsToAdd = ""
 
  foreach ($Path in $PathsToAdd) {
    if ($Env:Path -like "*$Path*") {
      echo "  Path to $Path already added"
    }
    else {
      $VerifiedPathsToAdd += ";$Path";echo "  Path to $Path needs to be added"
    }
  }
 
  if ($VerifiedPathsToAdd -ne "") {
    echo "Adding paths: $VerifiedPathsToAdd"
    [System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + "$VerifiedPathsToAdd","Machine")
    echo "Note: The new path does NOT take immediately in running processes. Only new processes will see new path."
  }
}
AddSystemPaths ("C:\java\bin")
# or
AddSystemPaths ("C:\java\bin","c:\TeamCity\bin")

Reference: http://blogs.technet.com/b/sqlthoughts/archive/2008/12/12/powershell-function-to-add-system-path.aspx

All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code PowerShell

Post navigation

Previous post
Next post

Related Posts

UNIX Terminal – Clear Bash History

Posted on October 28, 2015

history -cw All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept…

Read More

Bash – Suction (Move files from subfolders into parent)

Posted on April 9, 2018December 13, 2022

find . -mindepth 2 -type f -print -exec mv {} . \; # Delete empty directories find . -depth -empty -type d -exec rm -rfv {} \; Originally Posted on April 9, 2018Last Updated on December 13, 2022 All information on this site is shared with the intention to help….

Read More

Mac OSX Terminal – Get Mac Serial Number

Posted on June 17, 2016

A quick and easy way to get your serial number # Get Serial Number sSerialNumber=$(system_profiler SPHardwareDataType |grep "Serial Number (system)" |awk ‘{print $4}’ | cut -d/ -f1) echo $sSerialNumber All information on this site is shared with the intention to help. Before any source code or program is ran on…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • PowerShell - IIS Remove Site
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • PowerShell - IIS Remove Site
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories
  • Raspberry Pi - Remove Default Apps
  • PowerShell - Change Windows CD/DVD Drive Letter
©2025 David Kittell | WordPress Theme by SuperbThemes