Check If Folder Exists or Not in PowerShell

We can check and test if a folder exist or not by using the PowerShell cmdlet Test-Path.

The below powershell script will check whether the folder “C:Share” exists or not.

$dir = "C:\Share"
if (Test-Path $dir) 
{
  Write-Host "Folder Exists"
}
else
{
  Write-Host "Folder Not Exists"
}

Advertisement

Leave a Comment