We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script Repository

Check whether path exists

September 01, 2022 Views: 2084

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 script 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
Leave a comment
Loading...

Got questions?

Support Questions & Answers