Wednesday, July 19, 2006

PowerShell:Get a list of paths from the environment variable PATH

First of all, to get access to a variable from the environment you run:

$env:[variableName]

so, to get the PATH you do:

$env:path

on my machine, I get something like this:

PS C:\> $env:path
C:\oracle\product\10.1.0\Db_1\bin;C:\oracle\product\10.1.0\Db_1\jre\1.4.2\bin\c
lient;C:\oracle\product\10.1.0\Db_1\jre\1.4.2\bin;C:\Oracle\product\10.1.0\Clie
nt_1\bin;C:\Oracle\product\10.1.0\Client_1\jre\1.4.2\bin\client;C:\Oracle\produ
ct\10.1.0\Client_1\jre\1.4.2\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\Syst
em32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;c:\Program Files\
Microsoft SQL Server\90\Tools\binn\;C:\Program Files\QuickTime\QTSystem\;C:\Pro
gram Files\Support Tools\;C:\Program Files\Windows PowerShell\v1.0\
PS C:\>

that's kinda hard to read, so you can use this method instead:

$env:path.Split(';')

PS C:\> $env:path.Split(';')
C:\oracle\product\10.1.0\Db_1\bin
C:\oracle\product\10.1.0\Db_1\jre\1.4.2\bin\client
C:\oracle\product\10.1.0\Db_1\jre\1.4.2\bin
C:\Oracle\product\10.1.0\Client_1\bin
C:\Oracle\product\10.1.0\Client_1\jre\1.4.2\bin\client
C:\Oracle\product\10.1.0\Client_1\jre\1.4.2\bin
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\Program Files\Microsoft SQL Server\80\Tools\BINN
c:\Program Files\Microsoft SQL Server\90\Tools\binn\
C:\Program Files\QuickTime\QTSystem\
C:\Program Files\Support Tools\
C:\Program Files\Windows PowerShell\v1.0\
PS C:\>

ah... much better

what? you need the list on a file?

$env:path.Split(';') > list.txt

technorati tags:,

No comments: