PowerTip: Use PowerShell to Find File or Folder


Summary: Learn how to use Windows PowerShell to find a file or a folder.

Hey, Scripting Guy! Question How can I use Windows PowerShell to determine if a variable contains a path that leads to a file or folder?

Hey, Scripting Guy! Answer Use the Test-Path cmdlet to test the path stored in the variable, and then specify the PathType parameter,
           for example:

PS C:\> $fso = "c:\fso"

PS C:\> $file = "C:\fso\backup.ps1"

PS C:\> Test-Path $fso -PathType leaf

False

PS C:\> Test-Path $file -PathType leaf

True

Comments (0)

Skip to main content