/* ]]> */
Nov 132009
 

Sometimes it is useful to see what is in your system PATH environment variable to check for errors or duplicate entries or old junk that you don’t need in there anymore. However, the default view of PATH is one continuous string which is difficult to read.
DOS view:

C:\>path
PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;c:\program files\sysinternals;c:\program files\cr
imson editor;c:\program files\kstools;c:\Program Files\Microsoft SQL Server\90\Tools\binn\;c:\program files\jk
defrag;C:\Program Files\TortoiseSVN\bin;C:\Program Files\QuickTime\QTSystem\;C:\WINDOWS\system32\WindowsPowerS
hell\v1.0
C:\>

Since PowerShell has access to the .Net string data type and all it’s built-in methods, we can easily make the PATH environment variable contents much more readable by applying the “split” method, breaking apart each semi-colon delimited element.

PowerShell View:

?View Code POWERSHELL
PS C:\> gc -path env:path|% {$_.split(";")}
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
c:\program files\sysinternals
c:\program files\crimson editor
c:\program files\kstools
c:\Program Files\Microsoft SQL Server\90\Tools\binn\
c:\program files\jkdefrag
C:\Program Files\TortoiseSVN\bin
C:\Program Files\QuickTime\QTSystem\
C:\WINDOWS\system32\WindowsPowerShell\v1.0
PS C:\>

Now that’s much better!

 Posted by at 3:46 pm

  One Response to “Parse Your Path in PowerShell”

  1. Even shorter:
    $env:path | % {$_.split(“;”)}

    and still shorter:

    $env:path.split(“;”)

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Page optimized by WP Minify WordPress Plugin