views:

1133

answers:

1

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.

+3  A: 

Have you tried doing:

Dim de As New DirectoryEntry("LDAP://" & stringDN.Replace( "/", "\/" ))
Return CType(de.Properties("samaccountname")(0), String)
tvanfosson
That did indeed do it, though I needed only a single backslash: "\/"
rwmnau
Sorry -- C#-ism.
tvanfosson