Script Repository


Check whether path exists

June 30, 2017
1201

The script can be used with the If PowerShell script returns true condition to check whether a specific path exists. It returns True if all elements of the path exist and False if any are missing. The path can represent a file, a folder, a Windows Registry key or any other valid PowerShell provider path. For details, see Test-Path.

Parameter:

  • $path - specifies the path to check. You can use value references (e.g. %username%, %department%) in the path. When the script is executed, they are replaced with values of the AD object on which the zcript is run. For example, if you specify %username%, the value reference is replaced with the username of the user account on which the script is run.
Edit Remove
PowerShell
$path = "\\SERVER\Share\%username%" # TODO: modify me

$Context.ConditionIsMet = $False
try
{
    $pathExists = Test-Path -Path $path -ErrorAction Stop
}
catch
{
    return
}

if ($pathExists)
{
    $Context.ConditionIsMet = $True
}

Comments ( 0 )
No results found.
Leave a comment