"new DirectoryEntry(distinguishedName as string)" doesn't work when DN contains a "/"

2

I have the following code to convert a distinguishedName to a sAMAccountName:

Dim de As New DirectoryEntry("LDAP://" & stringDN)
Return CType(de.Properties("samaccountname")(0), String)

It works great for every DN I pass it, except for one. We have an AD group on our domain that has a "/" in it - call it "Programmers/DBAs". The DN for this group is "Programmers/DBAs,OU=User Groups,DC=mydomain,DC=local". When I try to use this DN as the stringDN above, I get a COMException of "Unknown error (0x80005000)".

Every other group/user in my domain works fine, and I've duplicated the issue on our test domain, where renaming the group so it doesn't contains a "/" resolves the problem. However, I'm not able to do this in production, so I'm stuck.

Can I escape this "/" somehow? I've got to believe there's a solution around this so that I can get the properties of this group properly.

vb.net
active-directory
directoryservices
directoryentry
distinguishedname
asked on Stack Overflow Feb 9, 2009 by SqlRyan

1 Answer

4

Have you tried doing:

Dim de As New DirectoryEntry("LDAP://" & stringDN.Replace( "/", "\/" ))
Return CType(de.Properties("samaccountname")(0), String)
answered on Stack Overflow Feb 9, 2009 by tvanfosson • edited Feb 9, 2009 by tvanfosson

User contributions licensed under CC BY-SA 3.0