PowerShell: Check if File Exists

If you writing a PowerShell Script and you want to check if a file exists or not, you can make use of the Test-Path cmdlet from the Microsoft.PowerShell.Management module.


    [-Path] <String[]>
    [-Filter <String>]
    [-Include <String[]>]
    [-Exclude <String[]>]
    [-PathType <TestPathType>]
    [-Credential <PSCredential>]
    [-OlderThan <DateTime>]
    [-NewerThan <DateTime>]


Test-Path 'C:\data\user\alan\records.csv'


You will see a boolean True|False based on whether the file exits or not.

PowerShell Check if File Exists or Not

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap