Skip to content

Instantly share code, notes, and snippets.

@VertigoRay
Last active December 20, 2015 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VertigoRay/6091753 to your computer and use it in GitHub Desktop.
Save VertigoRay/6091753 to your computer and use it in GitHub Desktop.
If you're possibly working with unclean data (or typo the DC structure) while checking if OU exists, you'll need to catch your errors.
[string] $Path = 'OU=foo,OU=test,DC=domain,DC=com'
try {
$ou_exists = [adsi]::Exists("LDAP://$Path")
} catch {
# If invalid format, error is thrown.
Throw("Supplied Path is invalid.`n$_")
}
if (-not $ou_exists) {
Throw('Supplied Path does not exist.')
} else {
Write-Debug "Path Exists: $Path"
}
@VertigoRay
Copy link
Author

Can't fork my own gist, so ...
https://gist.github.com/VertigoRay/6091801

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment