One liner code to check if file exists via PowerShell. Code below will check if Winrar.exe exist on the path specified. if (-not (test-path "$env:C:\Program Files\WinRAR\winrar.exe")) {write-host "File not found"; break;} {write-host "File Found" } Output will show "File Found" if winrar.exe exists on the path specified. The "break;" command on the code will cause the script to exit and not to continue to show "File Found" if the file doesn't exist. Or else it will be confusing to see the output. However, if the file can be found then the "File not Found" will not be shown. PowerShell will automatically bypass the first command on the { } curly braces and execute whatever is on the next line. Code below will check if output.txt exist on c:\temp. if (-not (test-path "$env:C:\temp\output.txt")) {write-host "File not found"; break;} {write-host "File Found" } Output ...
Make the world a better place by sharing knowledge, ideas and anything that you can give that comes from the heart.