Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - how to get a OU full address from AD

Reply
 
Old 07-24-2008   #1 (permalink)
how to get a OU full address from AD


 
 

how to get a OU full address from AD

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

My System SpecsSystem Spec
Old 07-27-2008   #2 (permalink)
OfficeGuyGoesWild


 
 

Re: how to get a OU full address from AD

On Jul 24, 4:05 pm, how to get a OU full address from AD <how to get a
OU full address from A...@xxxxxx> wrote:
Quote:

> 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)
My System SpecsSystem Spec
Old 07-29-2008   #3 (permalink)
Richard Mueller [MVP]


 
 

Re: how to get a OU full address from AD


"OfficeGuyGoesWild" <marty.lindsay@xxxxxx> wrote in message
news:cbb09358-ca64-4ff8-84db-4d67c90223a7@xxxxxx
Quote:

> On Jul 24, 4:05 pm, how to get a OU full address from AD <how to get a
> OU full address from A...@xxxxxx> wrote:
Quote:

>> 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
--


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Display of full email address Vista mail
full address Vista file management
Full path in the Address bar of Explorer??? Vista installation & setup
full email address as username Vista mail
Can I copy full paths from the address bar Vista file management


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46