Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

From the commandline,how can I look up an NT-style name using a distinguished name? That is, I want to put in "CN=Alice Smith,OU=Head Office,DC=Cyberdyne,DC=local" and get out "CYBERDYNE\ASmith"

Edit: Active Directory level 2003, if that matters.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

I think you are looking for the sAMAccountname ??

try the following...

dsquery * "CN=Alice Smith,OU=Head Office,DC=Cyberdyne,DC=local" -scope base -attr sAMAccountName

Although that does not get the DOMAIN\ prefix (CYBERDYNE)

Note: I think dsquery is installed on DC's only, you may have to grab a copy from a DC if you want to run it elsewhere...

.. Ken

share|improve this answer
    
Thanks, this gives the account name and I can derive the domain name from the Distinguishedname. (I can't see how to get the NT-style domain name programatically, but I'm only dealing with half a dozen domains here so I can just do that bit by hand) –  DrStalker Jul 20 '09 at 9:09

I missed getting to your question early enough, perhaps, to save you any of that "by hand" labor you mentioned in your comment to Ken Hughes. To do this programmatically you're looking at using the iADsNameTranslate interface. You can get a lot of mileage out of it for dealing translating the various possible names of an AD account (GUID, SID, samAccountName, displayName, DN, etc).

Example:

Option Explicit

' Constants for the iADsNameTranslate object. (from http://msdn.microsoft.com/en-us/library/aa772267(VS.85).aspx)
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1

Const ADS_NAME_INITTYPE_GC = 3

Dim objNameTranslate 
Dim strUsersamAccountName

' Create a nametranslate object and init to talk to a global catalog server
Set objNameTranslate = CreateObject("NameTranslate")
objNameTranslate.Init ADS_NAME_INITTYPE_GC, ""

' We're looking for a distinguished name, aka 1779
objNameTranslate.Set ADS_NAME_TYPE_1779, "CN=Bob, OU=blah, ..."

' Translate into the user's samAccountName
strUsersamAccountName = objNameTranslate.Get(ADS_NAME_TYPE_NT4)

WScript.Echo strUsersamAccountName
share|improve this answer
    
Thanks, this may coem in useful in future. –  DrStalker Jul 21 '09 at 9:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.