We can check and test if a file or folder exist or not by using the PowerShell cmdlet Test-Path.
The below powershell script will check whether the file test.txt is already exists or not under the path C:Share.
$FileName = "C:\Sharetest.txt"
if (Test-Path $FileName)
{
Write-Host "File Exists"
}
else
{
Write-Host "File Not Exists"
}
Advertisement