Test-Path Can Check More Than Files

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:\software\idera

Posted Jul 29 2009, 08:00 AM by ps1

Comments

Episode 79 – Listener Interviews « PowerScripting Podcast wrote Episode 79 – Listener Interviews « PowerScripting Podcast
on 08-09-2009 11:32 PM

Pingback from  Episode 79 – Listener Interviews «  PowerScripting Podcast

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.