Test-Path Can Check More Than Files

by Jul 29, 2009

Test-Path is your friend whenever you want to check whether a file or folder exists:

Test-Path C:autoexec.bat
Test-Path C:windows

Test-Path can check a lot of other things as well, though. It accepts any PowerShell drive, and as you may know, in PowerShell drives are not restricted to the filesystem.

To check whether an environment variable exists, use this:

Test-Path env:computername

To check for an alias, use this:

Test-Path alias:dir

You can even check for registry keys like this:

Test-Path hkcu:softwareidera