Last active
December 20, 2015 07:09
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can't fork my own gist, so ...
https://gist.github.com/VertigoRay/6091801