/* ]]> */
Dec 162009
 

This is a minor update to my previously posted path-parsing script but I think it’s useful enough to justify a repost. The addition here is to show a running count of each item found in the PATH environment variable. What makes this even more useful is adding it to your startup profile so the function can be called without the script-invoking format; e.g. “./path” – instead, you just type “path” at the command prompt.

Here’s the code as I have incorporated in to the profile script:

?View Code POWERSHELL
function split-path {
  $p = @(get-content env:path|% {$_.split(";")})
  "Path"
  "===="
  foreach ($p1 in $p){
    if ($p1.trim() -gt "") {
      $i+=1;
      "{0:D2} : {1}" -f $i,$p1
      }
    }
  ""
  }
#create an alias to call split-path
new-item -path alias:path -value split-path | out-null

Now, my output is nicely formatted with each item numbered and neatly aligned:

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS C:\powershell> path
Path
====
01 : C:\WINDOWS\system32
02 : C:\WINDOWS
03 : C:\WINDOWS\System32\Wbem
04 : c:\program files\sysinternals
05 : c:\program files\crimson editor
06 : c:\program files\kstools
07 : c:\Program Files\Microsoft SQL Server\90\Tools\binn\
08 : c:\program files\jkdefrag
09 : C:\Program Files\TortoiseSVN\bin
10 : C:\WINDOWS\system32\WindowsPowerShell\v1.0
11 : C:\Program Files\Scintilla Text Editor
12 : C:\Program Files\QuickTime\QTSystem\
PS C:\powershell>

 Posted by at 2:35 pm

 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