2.7 Verifying the Existence of a File or Folder
One of the primary uses of Test-Path is to verify the existence of a file or folder. For example, this command checks to see whether the file C:\Scripts\Test.txt exists:
Test-Path c:\scripts\test.txt
Test-Path returns True if the file exists, and returns False if the file does not exist.
As is usually the case with cmdlets, you can use wildcards with Test-Path. For example, this script tells you whether or not there are any .wma files in C:\Scripts:
Test-Path c:\scripts\*.wma
Did someone ask if you can you check for the existence of registry keys using Test-Path? Of course you can:
Test-Path HKCU:\Software\Microsoft\Windows\CurrentVersion