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.
Syntax:
Test-Path
[-Path] <String[]>
[-Filter <String>]
[-Include <String[]>]
[-Exclude <String[]>]
[-PathType <TestPathType>]
[-IsValid]
[-Credential <PSCredential>]
[-OlderThan <DateTime>]
[-NewerThan <DateTime>]
[<CommonParameters>]
Example:
Test-Path 'C:\data\user\alan\records.csv'
You will see a boolean True|False based on whether the file exits or not.

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!