-1

How can I check for the existence of an organizational unit without using the [adsi]::Exists() method? I can't for the life of me get it work on my system.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
user8056359
  • 437
  • 1
  • 7
  • 16

1 Answers1

0

The Exists() method requires an LDAP URI as its argument:

$ou = 'ou=foo,dc=example,dc=com'
[adsi]::Exists("LDAP://$ou")

If you want to use the Get-ADOrganizationalUnit cmdlet instead: use the -Filter parameter rather than the -Identity parameter. The former is usually more forgiving with AD cmdlets:

$ou = 'ou=foo,dc=example,dc=com'
Get-ADOrganizationalUnit -Filter "distinguishedName -eq '$ou'"
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328