I want get a full AD OU (e.g. computer) addess, how to do

Re: how to get a OU full address from AD by OfficeGuyGoesWild

OfficeGuyGoesWild
Sun Jul 27 16:07:57 CDT 2008

On Jul 24, 4:05 pm, how to get a OU full address from AD <how to get a
OU full address from A...@discussions.microsoft.com> wrote:
> I want get a full AD OU (e.g. computer) addess, how to do

This will give you the Distinguished name of the logged in user, which
may help get you started..


Set objADSystemInfo = CreateObject("ADSystemInfo")
x =
inputbox(objADSystemInfo.UserName,objADSystemInfo.UserName ,objADSystemInfo.UserName)

Re: how to get a OU full address from AD by Richard

Richard
Tue Jul 29 20:23:11 CDT 2008


"OfficeGuyGoesWild" <marty.lindsay@gmail.com> wrote in message
news:cbb09358-ca64-4ff8-84db-4d67c90223a7@j7g2000prm.googlegroups.com...
> On Jul 24, 4:05 pm, how to get a OU full address from AD <how to get a
> OU full address from A...@discussions.microsoft.com> wrote:
>> I want get a full AD OU (e.g. computer) addess, how to do
>
> This will give you the Distinguished name of the logged in user, which
> may help get you started..
>
>
> Set objADSystemInfo = CreateObject("ADSystemInfo")
> x =
> inputbox(objADSystemInfo.UserName,objADSystemInfo.UserName
> ,objADSystemInfo.UserName)

To get the Distinguished Name of the local computer:
=========
Option Explicit
Dim objSysInfo, strComputerDN

Set objSysInfo = CreateObject("ADSystemInfo")
strComputerDN = objSysInfo.ComputerName
Wscript.Echo strComputerDN
========
If all you have is the NetBIOS name of a computer, and you don't know where
in the hierarchy of Active Directory the object resides, you can use the
NameTranslate object. The Distinguished Name is the only attribute that
indicates this and shows the OU. For example, the following VBScript program
prompts for the NetBIOS name of a computer, determines the NetBIOS name of
the domain, and converts to the Distinguished Name. The trick for computer
objects is to realize that the sAMAccountName of the computer is the NetBIOS
name with a trailing "$" appended.
==========
Option Explicit
Dim objRootDSE, strDNSDomain, objTrans, strNetBIOSDomain
Dim strComputer, strComputerDN

' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1

' Determine DNS name of domain from RootDSE.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Use the NameTranslate object to find the NetBIOS domain name from the
' DNS domain name.
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
' Remove trailing backslash.
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)

' Prompt for the NetBIOS name of a computer.
strComputer = InputBox("Enter NetBIOS name of a computer", "Find OU")

' Use the Set method to specify the NT format of the computer name.
' The sAMAccountName of the computer is the NetBIOS name with trailing "$".
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strComputer & "$"

' Use the Get method to retrieve the Distinguished Name.
strComputerDN objTrans.Get(ADS_NAME_TYPE_1779)

Wscript.Echo "Computer Distinguished Name" _
& vbCrLf & strComputerDN
=========
For more information on the NameTranslate objects see this link:

http://www.rlmueller.net/NameTranslateFAQ.htm

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--