Just had a couple techs scratching their heads about finding the path.
Seriously? Yes.
But to be fair, the path can get long and downright hard to read. And that was the problem for our tech friends.
Now my friends are smart guys, but they had a problem with a path.
I can understand, since my path statement is over 800 characters, and nearly impossible to understand when read the normal way. They should have learned PowerShell. I’ll show you why, and it’s a great example of how PowerShell blows away other methods by being super easy and ultra flexible.
Everybody knows the normal way to find environment variables:
- Right clicking “Computer” –> Properties
- Advanced System Settings –> Advanced Tab –> Environment Variables
If you ever see me get the environment variables this way, you have my permission to punch me in the head.
Note: If the system I’m working on does not have PowerShell AND does not have Internet access, I’m going to punch you back
How To NOT Find The Path Environment Variable
- Search the registry for every instance of the word “PATH”.
- Open the computer case and search underneath the CPU fan.
- Reading tea leaves and/or chicken bones
There is a better way. Enter PowerShell
Check out this beauty:
PS C:> cd env:
PS Env:> ls path
And out comes the entry for the path variable
NAME VALUE
—— ——-
Path C:\windows\system32;C:\;C:\Sysinternals…
The path environment variable has 2 properties:
KEY
VALUE
You see here that “Name” is actually an alias for “Key”.
PS Env:\> ls path | gm
TypeName: System.Collections.DictionaryEntry
Name MemberType Definition
—- ———- ———-
Name AliasProperty Name = Key
…
(other methods and noteproperties)
…
Key Property System.Object Key {get;set;}
Value Property System.Object Value {get;set;}
If you want to see the actual value (what the path is), try this:
PS Env:> (ls path).value
If you want to see the individual lines in the path:
PS Env:> (ls path).value.split(“;”)
How many characters are in YOUR entire path statement? Find out!
PS Env:> (ls path).value.length
How many entries are in your path statement?
PS Env:> ((ls path).value.split(“;”) | measure).count
Just list the entries in the path that are in the windows directory and below:
(ls path).value.split(“;”) | ? {$_ -like “C:\Windows*” -or $_ -like “%systemroot%*”}
So now that the horse has been sufficiently beaten, I’ll sign off.
-Michael