Last active
December 20, 2015 07:09
-
-
Save VertigoRay/6091801 to your computer and use it in GitHub Desktop.
In my case, I only work within a particular OU in our Domain, so I’ve made it so my $Path can be abbreviated. Forked (https://gist.github.com/VertigoRay/6091753) ... here’s how I handle things:
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] $RootOU = 'OU=test,DC=domain,DC=com' | |
[string] $Path = 'OU=foo' | |
try { | |
$ou_exists = [adsi]::Exists("LDAP://$Path") | |
} catch { | |
# If invalid format, error is thrown. | |
Write-Debug "Supplied Path is invalid.`n$_" | |
# It's probably the abbreviated version, so let's tack on the Root OU and confirm exists. | |
Write-Debug 'Placing Path in Root OU and re-verifying ...' | |
$Path = "$Path,$RootOU" | |
try { | |
$ou_exists = [adsi]::Exists("LDAP://$Path") | |
} catch { | |
Throw("Supplied Path is not valid, nor is our attempt to place it in the Root OU:`n$Path") | |
} | |
} | |
if (-not $ou_exists) { | |
Throw("Supplied Path does not exist:`n$Path") | |
} else { | |
Write-Debug "Path Exists (1): $Path" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment