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:
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!
Even shorter:
$env:path | % {$_.split(“;”)}
and still shorter:
$env:path.split(“;”)