Q. How can I check if an Organization Unit exists in Active Directory using PowerShell?
A. The easiest way to check for an Organizational Unit is by checking via the ADSI interface and LDAP. Create a $path variable which is the fully distinguished name of the OU then check if it exists as follows:
[string] $Path = "OU=Labs,OU=NA,DC=savilltech,DC=net"
if(![adsi]::Exists("LDAP://$Path"))
{
}
In the example the subsequent code for the IF statement will run if the OU does not exist.
0 comments
Hide comments