If you use PowerShell a lot, there are going to be times that you need to import data from another file (like a list of servers from a text file to automate a task on many machines). This snippet sets a variable to a file path, tests the files location using the test-path function, and returns True if it exists and False if it does not.
If the file exists:
1 2 3 | $file = "m:\scripts\test.txt" $test = test-path $file $test |
True
If the file doesnt exist:
1 2 3 | $file = "m:\scripts\test2.txt" $test = test-path $file $test |
False
Tags: powershell