Hi There

Im trying to develop a VB script whereby an Input Box asks me to Enter
the name of a Active Directory Security Group and then writes the
CanonicalName of each member of that Group to a text file on my C:
Drive.

Can anyone help me on this. I really need it for determining where
users are located throughout our network.

Cheers

Des

Re: CanonicalName Query by Richard

Richard
Wed Nov 08 11:39:01 CST 2006

Des wrote:

> Im trying to develop a VB script whereby an Input Box asks me to Enter
> the name of a Active Directory Security Group and then writes the
> CanonicalName of each member of that Group to a text file on my C:
> Drive.
>
> Can anyone help me on this. I really need it for determining where
> users are located throughout our network.

First, you want the canonicalName attribute, which is constructed
(operational) and multi-valued. If you need the location of the group in the
hierarchy of AD it might make sense to retrieve the distinguishedName. Since
I assume you do not know where the object is, I assume you have the NetBIOS
name of the group (not the distinguishedName). I would use the NameTranslate
object to convert this to the distinguishedName.

Because canonical name is operational, you must use the GetInfoEx and Get
methods to retrieve the value. Also, because it is multi-valued, you must
retrieve it as an array. I think there is always one value in the array, but
I code for all possibilities. In the example below I output both
distinguishedName and canonicalName of all direct members of the group. You
can run the program at a command prompt with the cscript host and redirect
the output to a text file.
=============
Option Explicit

Dim objRootDSE, objTrans, strNetBIOSDomain, strNTName
Dim strGroupDN, strDNSDomain, objGroup, objMember, arrNames

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

strNTName = InputBox("Enter NetBIOS name of group", "Find Members")

' Determine DNS domain name from RootDSE object.
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_TYPE_NT4, strDNSDomain
objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
' Remove trailing backslash.
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)

' Use the NameTranslate object to convert the NetBIOS name of the group
' to the Distinguished Name required for the LDAP provider.
objTrans.Init ADS_NAME_INITTYPE_DOMAIN, strNetBIOSDomain
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779)

' Bind to the group object.
Set objGroup = GetObject("LDAP://" & strGroupDN)

' Enumerate direct members of the group.
For Each objMember In objGroup.Members
' Output Distinguished Name.
Wscript.Echo "DN: " & objMember.distinguishedName
' Output Canonical Name.
objMember.GetInfoEx Array("canonicalName"), 0
arrNames = objMember.Get("canonicalName")
If (TypeName(arrNames) = "String") Then
Wscript.Echo " " & arrNames
ElseIf Not IsEmpty(arrNames) Then
For k = 0 To UBound(arrNames)
Wscript.Echo " " & arrNames(k)
Next
Else
Wscript.Echo " <no canonical name>"
End If
Next

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net



Re: CanonicalName Query by d_mc_alister

d_mc_alister
Wed Nov 08 13:34:29 CST 2006

Richard

I cant believe the quick response I got!!!

This worked a treat!!! Exactly what I wanted.

Thanks again!!!

Des

Richard Mueller wrote:
> Des wrote:
>
> > Im trying to develop a VB script whereby an Input Box asks me to Enter
> > the name of a Active Directory Security Group and then writes the
> > CanonicalName of each member of that Group to a text file on my C:
> > Drive.
> >
> > Can anyone help me on this. I really need it for determining where
> > users are located throughout our network.
>
> First, you want the canonicalName attribute, which is constructed
> (operational) and multi-valued. If you need the location of the group in the
> hierarchy of AD it might make sense to retrieve the distinguishedName. Since
> I assume you do not know where the object is, I assume you have the NetBIOS
> name of the group (not the distinguishedName). I would use the NameTranslate
> object to convert this to the distinguishedName.
>
> Because canonical name is operational, you must use the GetInfoEx and Get
> methods to retrieve the value. Also, because it is multi-valued, you must
> retrieve it as an array. I think there is always one value in the array, but
> I code for all possibilities. In the example below I output both
> distinguishedName and canonicalName of all direct members of the group. You
> can run the program at a command prompt with the cscript host and redirect
> the output to a text file.
> =============
> Option Explicit
>
> Dim objRootDSE, objTrans, strNetBIOSDomain, strNTName
> Dim strGroupDN, strDNSDomain, objGroup, objMember, arrNames
>
> ' Constants for NameTranslate object.
> Const ADS_NAME_INITTYPE_DOMAIN = 1
> Const ADS_NAME_TYPE_NT4 = 3
> Const ADS_NAME_TYPE_1779 = 1
>
> strNTName = InputBox("Enter NetBIOS name of group", "Find Members")
>
> ' Determine DNS domain name from RootDSE object.
> 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_TYPE_NT4, strDNSDomain
> objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
> strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
> ' Remove trailing backslash.
> strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)
>
> ' Use the NameTranslate object to convert the NetBIOS name of the group
> ' to the Distinguished Name required for the LDAP provider.
> objTrans.Init ADS_NAME_INITTYPE_DOMAIN, strNetBIOSDomain
> objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
> strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779)
>
> ' Bind to the group object.
> Set objGroup = GetObject("LDAP://" & strGroupDN)
>
> ' Enumerate direct members of the group.
> For Each objMember In objGroup.Members
> ' Output Distinguished Name.
> Wscript.Echo "DN: " & objMember.distinguishedName
> ' Output Canonical Name.
> objMember.GetInfoEx Array("canonicalName"), 0
> arrNames = objMember.Get("canonicalName")
> If (TypeName(arrNames) = "String") Then
> Wscript.Echo " " & arrNames
> ElseIf Not IsEmpty(arrNames) Then
> For k = 0 To UBound(arrNames)
> Wscript.Echo " " & arrNames(k)
> Next
> Else
> Wscript.Echo " <no canonical name>"
> End If
> Next
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net


Re: CanonicalName Query by d_mc_alister

d_mc_alister
Fri Nov 10 03:21:46 CST 2006

Richard

I was wondering could you help me further. This script is great but I
would like it to do one more thing. Each user will be a member of
either Team A, Team B or Team C security groups. Is it possible that I
could export the Full Display Name of each user and also the
corresponding team they are in. Any help would be greatly appreciated.

Thanks

Des


d_mc_alister@hotmail.com wrote:

> Richard
>
> I cant believe the quick response I got!!!
>
> This worked a treat!!! Exactly what I wanted.
>
> Thanks again!!!
>
> Des
>
> Richard Mueller wrote:
> > Des wrote:
> >
> > > Im trying to develop a VB script whereby an Input Box asks me to Enter
> > > the name of a Active Directory Security Group and then writes the
> > > CanonicalName of each member of that Group to a text file on my C:
> > > Drive.
> > >
> > > Can anyone help me on this. I really need it for determining where
> > > users are located throughout our network.
> >
> > First, you want the canonicalName attribute, which is constructed
> > (operational) and multi-valued. If you need the location of the group in the
> > hierarchy of AD it might make sense to retrieve the distinguishedName. Since
> > I assume you do not know where the object is, I assume you have the NetBIOS
> > name of the group (not the distinguishedName). I would use the NameTranslate
> > object to convert this to the distinguishedName.
> >
> > Because canonical name is operational, you must use the GetInfoEx and Get
> > methods to retrieve the value. Also, because it is multi-valued, you must
> > retrieve it as an array. I think there is always one value in the array, but
> > I code for all possibilities. In the example below I output both
> > distinguishedName and canonicalName of all direct members of the group. You
> > can run the program at a command prompt with the cscript host and redirect
> > the output to a text file.
> > =============
> > Option Explicit
> >
> > Dim objRootDSE, objTrans, strNetBIOSDomain, strNTName
> > Dim strGroupDN, strDNSDomain, objGroup, objMember, arrNames
> >
> > ' Constants for NameTranslate object.
> > Const ADS_NAME_INITTYPE_DOMAIN = 1
> > Const ADS_NAME_TYPE_NT4 = 3
> > Const ADS_NAME_TYPE_1779 = 1
> >
> > strNTName = InputBox("Enter NetBIOS name of group", "Find Members")
> >
> > ' Determine DNS domain name from RootDSE object.
> > 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_TYPE_NT4, strDNSDomain
> > objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
> > strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
> > ' Remove trailing backslash.
> > strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)
> >
> > ' Use the NameTranslate object to convert the NetBIOS name of the group
> > ' to the Distinguished Name required for the LDAP provider.
> > objTrans.Init ADS_NAME_INITTYPE_DOMAIN, strNetBIOSDomain
> > objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
> > strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779)
> >
> > ' Bind to the group object.
> > Set objGroup = GetObject("LDAP://" & strGroupDN)
> >
> > ' Enumerate direct members of the group.
> > For Each objMember In objGroup.Members
> > ' Output Distinguished Name.
> > Wscript.Echo "DN: " & objMember.distinguishedName
> > ' Output Canonical Name.
> > objMember.GetInfoEx Array("canonicalName"), 0
> > arrNames = objMember.Get("canonicalName")
> > If (TypeName(arrNames) = "String") Then
> > Wscript.Echo " " & arrNames
> > ElseIf Not IsEmpty(arrNames) Then
> > For k = 0 To UBound(arrNames)
> > Wscript.Echo " " & arrNames(k)
> > Next
> > Else
> > Wscript.Echo " <no canonical name>"
> > End If
> > Next
> >
> > --
> > Richard
> > Microsoft MVP Scripting and ADSI
> > Hilltop Lab - http://www.rlmueller.net


Re: CanonicalName Query by Richard

Richard
Fri Nov 10 10:28:10 CST 2006

Once you have a reference to the user object corresponding to the member
(objMember in my code), you can retrieve any attribute values desired. I'm
not sure if you want the Common Name of the user, or the value of the
displayName attribute, so I retrieve both below. To test for group
membership you bind to the group object (using the Distinguished Name of the
group) and invoke the IsMember method. You pass the AdsPath of the
prospective member to the method, and it returns True if the corresponding
user is a member. For efficiency, I bind to the team group objects once
before looping through the membership. No need to bind over and over. You
can modify my solution below to meet your needs. I only include the parts
that changed, the loop of group members, binding to the 3 team groups, and
the Dim statement for the new variables:
=============
Dim objTeamA, objTeamB, objTeamC, strTeam

' Bind to groups for Team A, B, and C.
Set objTeamA = GetObject("LDAP://cn=Team A,cn=Users,dc=MyDomain,dc=com")
Set objTeamB = GetObject("LDAP://cn=Team B,cn=Users,dc=MyDomain,dc=com")
Set objTeamC = GetObject("LDAP://cn=Team C,cn=Users,dc=MyDomain,dc=com")

' Enumerate direct members of the group.
For Each objMember In objGroup.Members
' Output Distinguished Name.
Wscript.Echo "DN: " & objMember.distinguishedName
' Output Canonical Name.
objMember.GetInfoEx Array("canonicalName"), 0
arrNames = objMember.Get("canonicalName")
If (TypeName(arrNames) = "String") Then
Wscript.Echo " " & arrNames
ElseIf Not IsEmpty(arrNames) Then
For k = 0 To UBound(arrNames)
Wscript.Echo " " & arrNames(k)
Next
Else
Wscript.Echo " <no canonical name>"
End If
' Output Common Name and Display Name.
Wscript.Echo "CN = " & objMember.cn _
& ", DisplayName = " & objMember.displayName
' Output team membership.
strTeam = ""
If objTeamA.IsMember(objMember.AdsPath) Then
strTeam = strTeam & "TeamA"
End If
If objTeamB.IsMember(objMember.AdsPath) Then
strTeam = strTeam & "TeamB"
End If
If objTeamC.IsMember(objMember.AdsPath) Then
strTeam = strTeam & "TeamC"
End If
Wscript.Echo "Team membership: " & strTeam

Next

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

<d_mc_alister@hotmail.com> wrote in message
news:1163150506.772342.150010@h48g2000cwc.googlegroups.com...
> Richard
>
> I was wondering could you help me further. This script is great but I
> would like it to do one more thing. Each user will be a member of
> either Team A, Team B or Team C security groups. Is it possible that I
> could export the Full Display Name of each user and also the
> corresponding team they are in. Any help would be greatly appreciated.
>
> Thanks
>
> Des
>
>
> d_mc_alister@hotmail.com wrote:
>
>> Richard
>>
>> I cant believe the quick response I got!!!
>>
>> This worked a treat!!! Exactly what I wanted.
>>
>> Thanks again!!!
>>
>> Des
>>
>> Richard Mueller wrote:
>> > Des wrote:
>> >
>> > > Im trying to develop a VB script whereby an Input Box asks me to
>> > > Enter
>> > > the name of a Active Directory Security Group and then writes the
>> > > CanonicalName of each member of that Group to a text file on my C:
>> > > Drive.
>> > >
>> > > Can anyone help me on this. I really need it for determining where
>> > > users are located throughout our network.
>> >
>> > First, you want the canonicalName attribute, which is constructed
>> > (operational) and multi-valued. If you need the location of the group
>> > in the
>> > hierarchy of AD it might make sense to retrieve the distinguishedName.
>> > Since
>> > I assume you do not know where the object is, I assume you have the
>> > NetBIOS
>> > name of the group (not the distinguishedName). I would use the
>> > NameTranslate
>> > object to convert this to the distinguishedName.
>> >
>> > Because canonical name is operational, you must use the GetInfoEx and
>> > Get
>> > methods to retrieve the value. Also, because it is multi-valued, you
>> > must
>> > retrieve it as an array. I think there is always one value in the
>> > array, but
>> > I code for all possibilities. In the example below I output both
>> > distinguishedName and canonicalName of all direct members of the group.
>> > You
>> > can run the program at a command prompt with the cscript host and
>> > redirect
>> > the output to a text file.
>> > =============
>> > Option Explicit
>> >
>> > Dim objRootDSE, objTrans, strNetBIOSDomain, strNTName
>> > Dim strGroupDN, strDNSDomain, objGroup, objMember, arrNames
>> >
>> > ' Constants for NameTranslate object.
>> > Const ADS_NAME_INITTYPE_DOMAIN = 1
>> > Const ADS_NAME_TYPE_NT4 = 3
>> > Const ADS_NAME_TYPE_1779 = 1
>> >
>> > strNTName = InputBox("Enter NetBIOS name of group", "Find Members")
>> >
>> > ' Determine DNS domain name from RootDSE object.
>> > 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_TYPE_NT4, strDNSDomain
>> > objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
>> > strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
>> > ' Remove trailing backslash.
>> > strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)
>> >
>> > ' Use the NameTranslate object to convert the NetBIOS name of the group
>> > ' to the Distinguished Name required for the LDAP provider.
>> > objTrans.Init ADS_NAME_INITTYPE_DOMAIN, strNetBIOSDomain
>> > objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
>> > strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779)
>> >
>> > ' Bind to the group object.
>> > Set objGroup = GetObject("LDAP://" & strGroupDN)
>> >
>> > ' Enumerate direct members of the group.
>> > For Each objMember In objGroup.Members
>> > ' Output Distinguished Name.
>> > Wscript.Echo "DN: " & objMember.distinguishedName
>> > ' Output Canonical Name.
>> > objMember.GetInfoEx Array("canonicalName"), 0
>> > arrNames = objMember.Get("canonicalName")
>> > If (TypeName(arrNames) = "String") Then
>> > Wscript.Echo " " & arrNames
>> > ElseIf Not IsEmpty(arrNames) Then
>> > For k = 0 To UBound(arrNames)
>> > Wscript.Echo " " & arrNames(k)
>> > Next
>> > Else
>> > Wscript.Echo " <no canonical name>"
>> > End If
>> > Next
>> >
>> > --
>> > Richard
>> > Microsoft MVP Scripting and ADSI
>> > Hilltop Lab - http://www.rlmueller.net
>



Re: CanonicalName Query by d_mc_alister

d_mc_alister
Fri Nov 10 11:18:37 CST 2006

Thanks So Much Richard for getting back so quick.

I've tried the Script but now Im getting the following error at this
line (If objTeamB.IsMember(objMember.AdsPath) Then ) Im not sure why it
wants quotation marks?? Any ideas?

Microsoft VBScript runtime error: Object required: ''

Thanks

Des


Richard Mueller wrote:
> Once you have a reference to the user object corresponding to the member
> (objMember in my code), you can retrieve any attribute values desired. I'm
> not sure if you want the Common Name of the user, or the value of the
> displayName attribute, so I retrieve both below. To test for group
> membership you bind to the group object (using the Distinguished Name of the
> group) and invoke the IsMember method. You pass the AdsPath of the
> prospective member to the method, and it returns True if the corresponding
> user is a member. For efficiency, I bind to the team group objects once
> before looping through the membership. No need to bind over and over. You
> can modify my solution below to meet your needs. I only include the parts
> that changed, the loop of group members, binding to the 3 team groups, and
> the Dim statement for the new variables:
> =============
> Dim objTeamA, objTeamB, objTeamC, strTeam
>
> ' Bind to groups for Team A, B, and C.
> Set objTeamA = GetObject("LDAP://cn=Team A,cn=Users,dc=MyDomain,dc=com")
> Set objTeamB = GetObject("LDAP://cn=Team B,cn=Users,dc=MyDomain,dc=com")
> Set objTeamC = GetObject("LDAP://cn=Team C,cn=Users,dc=MyDomain,dc=com")
>
> ' Enumerate direct members of the group.
> For Each objMember In objGroup.Members
> ' Output Distinguished Name.
> Wscript.Echo "DN: " & objMember.distinguishedName
> ' Output Canonical Name.
> objMember.GetInfoEx Array("canonicalName"), 0
> arrNames = objMember.Get("canonicalName")
> If (TypeName(arrNames) = "String") Then
> Wscript.Echo " " & arrNames
> ElseIf Not IsEmpty(arrNames) Then
> For k = 0 To UBound(arrNames)
> Wscript.Echo " " & arrNames(k)
> Next
> Else
> Wscript.Echo " <no canonical name>"
> End If
> ' Output Common Name and Display Name.
> Wscript.Echo "CN = " & objMember.cn _
> & ", DisplayName = " & objMember.displayName
> ' Output team membership.
> strTeam = ""
> If objTeamA.IsMember(objMember.AdsPath) Then
> strTeam = strTeam & "TeamA"
> End If
> If objTeamB.IsMember(objMember.AdsPath) Then
> strTeam = strTeam & "TeamB"
> End If
> If objTeamC.IsMember(objMember.AdsPath) Then
> strTeam = strTeam & "TeamC"
> End If
> Wscript.Echo "Team membership: " & strTeam
>
> Next
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
>
> <d_mc_alister@hotmail.com> wrote in message
> news:1163150506.772342.150010@h48g2000cwc.googlegroups.com...
> > Richard
> >
> > I was wondering could you help me further. This script is great but I
> > would like it to do one more thing. Each user will be a member of
> > either Team A, Team B or Team C security groups. Is it possible that I
> > could export the Full Display Name of each user and also the
> > corresponding team they are in. Any help would be greatly appreciated.
> >
> > Thanks
> >
> > Des
> >
> >
> > d_mc_alister@hotmail.com wrote:
> >
> >> Richard
> >>
> >> I cant believe the quick response I got!!!
> >>
> >> This worked a treat!!! Exactly what I wanted.
> >>
> >> Thanks again!!!
> >>
> >> Des
> >>
> >> Richard Mueller wrote:
> >> > Des wrote:
> >> >
> >> > > Im trying to develop a VB script whereby an Input Box asks me to
> >> > > Enter
> >> > > the name of a Active Directory Security Group and then writes the
> >> > > CanonicalName of each member of that Group to a text file on my C:
> >> > > Drive.
> >> > >
> >> > > Can anyone help me on this. I really need it for determining where
> >> > > users are located throughout our network.
> >> >
> >> > First, you want the canonicalName attribute, which is constructed
> >> > (operational) and multi-valued. If you need the location of the group
> >> > in the
> >> > hierarchy of AD it might make sense to retrieve the distinguishedName.
> >> > Since
> >> > I assume you do not know where the object is, I assume you have the
> >> > NetBIOS
> >> > name of the group (not the distinguishedName). I would use the
> >> > NameTranslate
> >> > object to convert this to the distinguishedName.
> >> >
> >> > Because canonical name is operational, you must use the GetInfoEx and
> >> > Get
> >> > methods to retrieve the value. Also, because it is multi-valued, you
> >> > must
> >> > retrieve it as an array. I think there is always one value in the
> >> > array, but
> >> > I code for all possibilities. In the example below I output both
> >> > distinguishedName and canonicalName of all direct members of the group.
> >> > You
> >> > can run the program at a command prompt with the cscript host and
> >> > redirect
> >> > the output to a text file.
> >> > =============
> >> > Option Explicit
> >> >
> >> > Dim objRootDSE, objTrans, strNetBIOSDomain, strNTName
> >> > Dim strGroupDN, strDNSDomain, objGroup, objMember, arrNames
> >> >
> >> > ' Constants for NameTranslate object.
> >> > Const ADS_NAME_INITTYPE_DOMAIN = 1
> >> > Const ADS_NAME_TYPE_NT4 = 3
> >> > Const ADS_NAME_TYPE_1779 = 1
> >> >
> >> > strNTName = InputBox("Enter NetBIOS name of group", "Find Members")
> >> >
> >> > ' Determine DNS domain name from RootDSE object.
> >> > 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_TYPE_NT4, strDNSDomain
> >> > objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
> >> > strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
> >> > ' Remove trailing backslash.
> >> > strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)
> >> >
> >> > ' Use the NameTranslate object to convert the NetBIOS name of the group
> >> > ' to the Distinguished Name required for the LDAP provider.
> >> > objTrans.Init ADS_NAME_INITTYPE_DOMAIN, strNetBIOSDomain
> >> > objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
> >> > strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779)
> >> >
> >> > ' Bind to the group object.
> >> > Set objGroup = GetObject("LDAP://" & strGroupDN)
> >> >
> >> > ' Enumerate direct members of the group.
> >> > For Each objMember In objGroup.Members
> >> > ' Output Distinguished Name.
> >> > Wscript.Echo "DN: " & objMember.distinguishedName
> >> > ' Output Canonical Name.
> >> > objMember.GetInfoEx Array("canonicalName"), 0
> >> > arrNames = objMember.Get("canonicalName")
> >> > If (TypeName(arrNames) = "String") Then
> >> > Wscript.Echo " " & arrNames
> >> > ElseIf Not IsEmpty(arrNames) Then
> >> > For k = 0 To UBound(arrNames)
> >> > Wscript.Echo " " & arrNames(k)
> >> > Next
> >> > Else
> >> > Wscript.Echo " <no canonical name>"
> >> > End If
> >> > Next
> >> >
> >> > --
> >> > Richard
> >> > Microsoft MVP Scripting and ADSI
> >> > Hilltop Lab - http://www.rlmueller.net
> >


Re: CanonicalName Query by d_mc_alister

d_mc_alister
Fri Nov 10 11:31:05 CST 2006

Richard

It would probably help if I show you the full text of the script

Option Explicit


Dim objRootDSE, objTrans, strNetBIOSDomain, strNTName
Dim strGroupDN, strDNSDomain, objGroup, objMember, arrNames


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


strNTName = InputBox("Enter NetBIOS name of group", "Find Members")


' Determine DNS domain name from RootDSE object.
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_TYPE_NT4, strDNSDomain
objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
' Remove trailing backslash.
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)


' Use the NameTranslate object to convert the NetBIOS name of the group

' to the Distinguished Name required for the LDAP provider.
objTrans.Init ADS_NAME_INITTYPE_DOMAIN, strNetBIOSDomain
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779)


' Bind to the group object.
Set objGroup = GetObject("LDAP://" & strGroupDN)

Dim objTeamA, objTeamB, objTeamC, strTeam

' Bind to groups for Team A, B, and C.
Set objTeamA = GetObject("LDAP://cn=Padiham Team,OU=Distribution Groups
Padiham,OU=Distribution Groups,dc=hml,dc=co,dc=uk")


' Enumerate direct members of the group.
For Each objMember In objGroup.Members
' Output Distinguished Name.
Wscript.Echo "DN: " & objMember.distinguishedName
' Output Canonical Name.
objMember.GetInfoEx Array("canonicalName"), 0
arrNames = objMember.Get("canonicalName")
If (TypeName(arrNames) = "String") Then
Wscript.Echo " " & arrNames
ElseIf Not IsEmpty(arrNames) Then
For k = 0 To UBound(arrNames)
Wscript.Echo " " & arrNames(k)
Next
Else
Wscript.Echo " <no canonical name>"
End If
' Output Common Name and Display Name.
Wscript.Echo "CN = " & objMember.cn _
& ", DisplayName = " & objMember.displayName
' Output team membership.
strTeam = ""
If objTeamA.IsMember(objMember.AdsPath) Then
strTeam = strTeam & "TeamA"
End If
If objTeamB.IsMember(objMember.AdsPath) Then
strTeam = strTeam & "TeamB"
End If
If objTeamC.IsMember(objMember.AdsPath) Then
strTeam = strTeam & "TeamC"
End If
Wscript.Echo "Team membership: " & strTeam


Next


Thanks

Des

d_mc_alister@hotmail.com wrote:
> Thanks So Much Richard for getting back so quick.
>
> I've tried the Script but now Im getting the following error at this
> line (If objTeamB.IsMember(objMember.AdsPath) Then ) Im not sure why it
> wants quotation marks?? Any ideas?
>
> Microsoft VBScript runtime error: Object required: ''
>
> Thanks
>
> Des
>
>
> Richard Mueller wrote:
> > Once you have a reference to the user object corresponding to the member
> > (objMember in my code), you can retrieve any attribute values desired. I'm
> > not sure if you want the Common Name of the user, or the value of the
> > displayName attribute, so I retrieve both below. To test for group
> > membership you bind to the group object (using the Distinguished Name of the
> > group) and invoke the IsMember method. You pass the AdsPath of the
> > prospective member to the method, and it returns True if the corresponding
> > user is a member. For efficiency, I bind to the team group objects once
> > before looping through the membership. No need to bind over and over. You
> > can modify my solution below to meet your needs. I only include the parts
> > that changed, the loop of group members, binding to the 3 team groups, and
> > the Dim statement for the new variables:
> > =============
> > Dim objTeamA, objTeamB, objTeamC, strTeam
> >
> > ' Bind to groups for Team A, B, and C.
> > Set objTeamA = GetObject("LDAP://cn=Team A,cn=Users,dc=MyDomain,dc=com")
> > Set objTeamB = GetObject("LDAP://cn=Team B,cn=Users,dc=MyDomain,dc=com")
> > Set objTeamC = GetObject("LDAP://cn=Team C,cn=Users,dc=MyDomain,dc=com")
> >
> > ' Enumerate direct members of the group.
> > For Each objMember In objGroup.Members
> > ' Output Distinguished Name.
> > Wscript.Echo "DN: " & objMember.distinguishedName
> > ' Output Canonical Name.
> > objMember.GetInfoEx Array("canonicalName"), 0
> > arrNames = objMember.Get("canonicalName")
> > If (TypeName(arrNames) = "String") Then
> > Wscript.Echo " " & arrNames
> > ElseIf Not IsEmpty(arrNames) Then
> > For k = 0 To UBound(arrNames)
> > Wscript.Echo " " & arrNames(k)
> > Next
> > Else
> > Wscript.Echo " <no canonical name>"
> > End If
> > ' Output Common Name and Display Name.
> > Wscript.Echo "CN = " & objMember.cn _
> > & ", DisplayName = " & objMember.displayName
> > ' Output team membership.
> > strTeam = ""
> > If objTeamA.IsMember(objMember.AdsPath) Then
> > strTeam = strTeam & "TeamA"
> > End If
> > If objTeamB.IsMember(objMember.AdsPath) Then
> > strTeam = strTeam & "TeamB"
> > End If
> > If objTeamC.IsMember(objMember.AdsPath) Then
> > strTeam = strTeam & "TeamC"
> > End If
> > Wscript.Echo "Team membership: " & strTeam
> >
> > Next
> >
> > --
> > Richard
> > Microsoft MVP Scripting and ADSI
> > Hilltop Lab - http://www.rlmueller.net
> >
> > <d_mc_alister@hotmail.com> wrote in message
> > news:1163150506.772342.150010@h48g2000cwc.googlegroups.com...
> > > Richard
> > >
> > > I was wondering could you help me further. This script is great but I
> > > would like it to do one more thing. Each user will be a member of
> > > either Team A, Team B or Team C security groups. Is it possible that I
> > > could export the Full Display Name of each user and also the
> > > corresponding team they are in. Any help would be greatly appreciated.
> > >
> > > Thanks
> > >
> > > Des
> > >
> > >
> > > d_mc_alister@hotmail.com wrote:
> > >
> > >> Richard
> > >>
> > >> I cant believe the quick response I got!!!
> > >>
> > >> This worked a treat!!! Exactly what I wanted.
> > >>
> > >> Thanks again!!!
> > >>
> > >> Des
> > >>
> > >> Richard Mueller wrote:
> > >> > Des wrote:
> > >> >
> > >> > > Im trying to develop a VB script whereby an Input Box asks me to
> > >> > > Enter
> > >> > > the name of a Active Directory Security Group and then writes the
> > >> > > CanonicalName of each member of that Group to a text file on my C:
> > >> > > Drive.
> > >> > >
> > >> > > Can anyone help me on this. I really need it for determining where
> > >> > > users are located throughout our network.
> > >> >
> > >> > First, you want the canonicalName attribute, which is constructed
> > >> > (operational) and multi-valued. If you need the location of the group
> > >> > in the
> > >> > hierarchy of AD it might make sense to retrieve the distinguishedName.
> > >> > Since
> > >> > I assume you do not know where the object is, I assume you have the
> > >> > NetBIOS
> > >> > name of the group (not the distinguishedName). I would use the
> > >> > NameTranslate
> > >> > object to convert this to the distinguishedName.
> > >> >
> > >> > Because canonical name is operational, you must use the GetInfoEx and
> > >> > Get
> > >> > methods to retrieve the value. Also, because it is multi-valued, you
> > >> > must
> > >> > retrieve it as an array. I think there is always one value in the
> > >> > array, but
> > >> > I code for all possibilities. In the example below I output both
> > >> > distinguishedName and canonicalName of all direct members of the group.
> > >> > You
> > >> > can run the program at a command prompt with the cscript host and
> > >> > redirect
> > >> > the output to a text file.
> > >> > =============
> > >> > Option Explicit
> > >> >
> > >> > Dim objRootDSE, objTrans, strNetBIOSDomain, strNTName
> > >> > Dim strGroupDN, strDNSDomain, objGroup, objMember, arrNames
> > >> >
> > >> > ' Constants for NameTranslate object.
> > >> > Const ADS_NAME_INITTYPE_DOMAIN = 1
> > >> > Const ADS_NAME_TYPE_NT4 = 3
> > >> > Const ADS_NAME_TYPE_1779 = 1
> > >> >
> > >> > strNTName = InputBox("Enter NetBIOS name of group", "Find Members")
> > >> >
> > >> > ' Determine DNS domain name from RootDSE object.
> > >> > 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_TYPE_NT4, strDNSDomain
> > >> > objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
> > >> > strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
> > >> > ' Remove trailing backslash.
> > >> > strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)
> > >> >
> > >> > ' Use the NameTranslate object to convert the NetBIOS name of the group
> > >> > ' to the Distinguished Name required for the LDAP provider.
> > >> > objTrans.Init ADS_NAME_INITTYPE_DOMAIN, strNetBIOSDomain
> > >> > objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
> > >> > strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779)
> > >> >
> > >> > ' Bind to the group object.
> > >> > Set objGroup = GetObject("LDAP://" & strGroupDN)
> > >> >
> > >> > ' Enumerate direct members of the group.
> > >> > For Each objMember In objGroup.Members
> > >> > ' Output Distinguished Name.
> > >> > Wscript.Echo "DN: " & objMember.distinguishedName
> > >> > ' Output Canonical Name.
> > >> > objMember.GetInfoEx Array("canonicalName"), 0
> > >> > arrNames = objMember.Get("canonicalName")
> > >> > If (TypeName(arrNames) = "String") Then
> > >> > Wscript.Echo " " & arrNames
> > >> > ElseIf Not IsEmpty(arrNames) Then
> > >> > For k = 0 To UBound(arrNames)
> > >> > Wscript.Echo " " & arrNames(k)
> > >> > Next
> > >> > Else
> > >> > Wscript.Echo " <no canonical name>"
> > >> > End If
> > >> > Next
> > >> >
> > >> > --
> > >> > Richard
> > >> > Microsoft MVP Scripting and ADSI
> > >> > Hilltop Lab - http://www.rlmueller.net
> > >


Re: CanonicalName Query by Richard

Richard
Fri Nov 10 11:45:33 CST 2006

I believe you created a reference to TeamA, but not to TeamB and TeamC. You
need to bind to objTeamB and objTeamC, similar to what you did for objTeamA.
Since you did not bind objTeamB, the error is raised when you attempt to
invoke a method of objTeamB, indicating that objTeamB must be an object
created with a Set statement.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

<d_mc_alister@hotmail.com> wrote in message
news:1163179865.588558.122920@e3g2000cwe.googlegroups.com...
> Richard
>
> It would probably help if I show you the full text of the script
>
> Option Explicit
>
>
> Dim objRootDSE, objTrans, strNetBIOSDomain, strNTName
> Dim strGroupDN, strDNSDomain, objGroup, objMember, arrNames
>
>
> ' Constants for NameTranslate object.
> Const ADS_NAME_INITTYPE_DOMAIN = 1
> Const ADS_NAME_TYPE_NT4 = 3
> Const ADS_NAME_TYPE_1779 = 1
>
>
> strNTName = InputBox("Enter NetBIOS name of group", "Find Members")
>
>
> ' Determine DNS domain name from RootDSE object.
> 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_TYPE_NT4, strDNSDomain
> objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
> strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
> ' Remove trailing backslash.
> strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)
>
>
> ' Use the NameTranslate object to convert the NetBIOS name of the group
>
> ' to the Distinguished Name required for the LDAP provider.
> objTrans.Init ADS_NAME_INITTYPE_DOMAIN, strNetBIOSDomain
> objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
> strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779)
>
>
> ' Bind to the group object.
> Set objGroup = GetObject("LDAP://" & strGroupDN)
>
> Dim objTeamA, objTeamB, objTeamC, strTeam
>
> ' Bind to groups for Team A, B, and C.
> Set objTeamA = GetObject("LDAP://cn=Padiham Team,OU=Distribution Groups
> Padiham,OU=Distribution Groups,dc=hml,dc=co,dc=uk")
>
>
> ' Enumerate direct members of the group.
> For Each objMember In objGroup.Members
> ' Output Distinguished Name.
> Wscript.Echo "DN: " & objMember.distinguishedName
> ' Output Canonical Name.
> objMember.GetInfoEx Array("canonicalName"), 0
> arrNames = objMember.Get("canonicalName")
> If (TypeName(arrNames) = "String") Then
> Wscript.Echo " " & arrNames
> ElseIf Not IsEmpty(arrNames) Then
> For k = 0 To UBound(arrNames)
> Wscript.Echo " " & arrNames(k)
> Next
> Else
> Wscript.Echo " <no canonical name>"
> End If
> ' Output Common Name and Display Name.
> Wscript.Echo "CN = " & objMember.cn _
> & ", DisplayName = " & objMember.displayName
> ' Output team membership.
> strTeam = ""
> If objTeamA.IsMember(objMember.AdsPath) Then
> strTeam = strTeam & "TeamA"
> End If
> If objTeamB.IsMember(objMember.AdsPath) Then
> strTeam = strTeam & "TeamB"
> End If
> If objTeamC.IsMember(objMember.AdsPath) Then
> strTeam = strTeam & "TeamC"
> End If
> Wscript.Echo "Team membership: " & strTeam
>
>
> Next
>
>
> Thanks
>
> Des
>
> d_mc_alister@hotmail.com wrote:
>> Thanks So Much Richard for getting back so quick.
>>
>> I've tried the Script but now Im getting the following error at this
>> line (If objTeamB.IsMember(objMember.AdsPath) Then ) Im not sure why it
>> wants quotation marks?? Any ideas?
>>
>> Microsoft VBScript runtime error: Object required: ''
>>
>> Thanks
>>
>> Des
>>
>>
>> Richard Mueller wrote:
>> > Once you have a reference to the user object corresponding to the
>> > member
>> > (objMember in my code), you can retrieve any attribute values desired.
>> > I'm
>> > not sure if you want the Common Name of the user, or the value of the
>> > displayName attribute, so I retrieve both below. To test for group
>> > membership you bind to the group object (using the Distinguished Name
>> > of the
>> > group) and invoke the IsMember method. You pass the AdsPath of the
>> > prospective member to the method, and it returns True if the
>> > corresponding
>> > user is a member. For efficiency, I bind to the team group objects once
>> > before looping through the membership. No need to bind over and over.
>> > You
>> > can modify my solution below to meet your needs. I only include the
>> > parts
>> > that changed, the loop of group members, binding to the 3 team groups,
>> > and
>> > the Dim statement for the new variables:
>> > =============
>> > Dim objTeamA, objTeamB, objTeamC, strTeam
>> >
>> > ' Bind to groups for Team A, B, and C.
>> > Set objTeamA = GetObject("LDAP://cn=Team
>> > A,cn=Users,dc=MyDomain,dc=com")
>> > Set objTeamB = GetObject("LDAP://cn=Team
>> > B,cn=Users,dc=MyDomain,dc=com")
>> > Set objTeamC = GetObject("LDAP://cn=Team
>> > C,cn=Users,dc=MyDomain,dc=com")
>> >
>> > ' Enumerate direct members of the group.
>> > For Each objMember In objGroup.Members
>> > ' Output Distinguished Name.
>> > Wscript.Echo "DN: " & objMember.distinguishedName
>> > ' Output Canonical Name.
>> > objMember.GetInfoEx Array("canonicalName"), 0
>> > arrNames = objMember.Get("canonicalName")
>> > If (TypeName(arrNames) = "String") Then
>> > Wscript.Echo " " & arrNames
>> > ElseIf Not IsEmpty(arrNames) Then
>> > For k = 0 To UBound(arrNames)
>> > Wscript.Echo " " & arrNames(k)
>> > Next
>> > Else
>> > Wscript.Echo " <no canonical name>"
>> > End If
>> > ' Output Common Name and Display Name.
>> > Wscript.Echo "CN = " & objMember.cn _
>> > & ", DisplayName = " & objMember.displayName
>> > ' Output team membership.
>> > strTeam = ""
>> > If objTeamA.IsMember(objMember.AdsPath) Then
>> > strTeam = strTeam & "TeamA"
>> > End If
>> > If objTeamB.IsMember(objMember.AdsPath) Then
>> > strTeam = strTeam & "TeamB"
>> > End If
>> > If objTeamC.IsMember(objMember.AdsPath) Then
>> > strTeam = strTeam & "TeamC"
>> > End If
>> > Wscript.Echo "Team membership: " & strTeam
>> >
>> > Next
>> >
>> > --
>> > Richard
>> > Microsoft MVP Scripting and ADSI
>> > Hilltop Lab - http://www.rlmueller.net
>> >
>> > <d_mc_alister@hotmail.com> wrote in message
>> > news:1163150506.772342.150010@h48g2000cwc.googlegroups.com...
>> > > Richard
>> > >
>> > > I was wondering could you help me further. This script is great but I
>> > > would like it to do one more thing. Each user will be a member of
>> > > either Team A, Team B or Team C security groups. Is it possible that
>> > > I
>> > > could export the Full Display Name of each user and also the
>> > > corresponding team they are in. Any help would be greatly
>> > > appreciated.
>> > >
>> > > Thanks
>> > >
>> > > Des
>> > >
>> > >
>> > > d_mc_alister@hotmail.com wrote:
>> > >
>> > >> Richard
>> > >>
>> > >> I cant believe the quick response I got!!!
>> > >>
>> > >> This worked a treat!!! Exactly what I wanted.
>> > >>
>> > >> Thanks again!!!
>> > >>
>> > >> Des
>> > >>
>> > >> Richard Mueller wrote:
>> > >> > Des wrote:
>> > >> >
>> > >> > > Im trying to develop a VB script whereby an Input Box asks me to
>> > >> > > Enter
>> > >> > > the name of a Active Directory Security Group and then writes
>> > >> > > the
>> > >> > > CanonicalName of each member of that Group to a text file on my
>> > >> > > C:
>> > >> > > Drive.
>> > >> > >
>> > >> > > Can anyone help me on this. I really need it for determining
>> > >> > > where
>> > >> > > users are located throughout our network.
>> > >> >
>> > >> > First, you want the canonicalName attribute, which is constructed
>> > >> > (operational) and multi-valued. If you need the location of the
>> > >> > group
>> > >> > in the
>> > >> > hierarchy of AD it might make sense to retrieve the
>> > >> > distinguishedName.
>> > >> > Since
>> > >> > I assume you do not know where the object is, I assume you have
>> > >> > the
>> > >> > NetBIOS
>> > >> > name of the group (not the distinguishedName). I would use the
>> > >> > NameTranslate
>> > >> > object to convert this to the distinguishedName.
>> > >> >
>> > >> > Because canonical name is operational, you must use the GetInfoEx
>> > >> > and
>> > >> > Get
>> > >> > methods to retrieve the value. Also, because it is multi-valued,
>> > >> > you
>> > >> > must
>> > >> > retrieve it as an array. I think there is always one value in the
>> > >> > array, but
>> > >> > I code for all possibilities. In the example below I output both
>> > >> > distinguishedName and canonicalName of all direct members of the
>> > >> > group.
>> > >> > You
>> > >> > can run the program at a command prompt with the cscript host and
>> > >> > redirect
>> > >> > the output to a text file.
>> > >> > =============
>> > >> > Option Explicit
>> > >> >
>> > >> > Dim objRootDSE, objTrans, strNetBIOSDomain, strNTName
>> > >> > Dim strGroupDN, strDNSDomain, objGroup, objMember, arrNames
>> > >> >
>> > >> > ' Constants for NameTranslate object.
>> > >> > Const ADS_NAME_INITTYPE_DOMAIN = 1
>> > >> > Const ADS_NAME_TYPE_NT4 = 3
>> > >> > Const ADS_NAME_TYPE_1779 = 1
>> > >> >
>> > >> > strNTName = InputBox("Enter NetBIOS name of group", "Find
>> > >> > Members")
>> > >> >
>> > >> > ' Determine DNS domain name from RootDSE object.
>> > >> > 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_TYPE_NT4, strDNSDomain
>> > >> > objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
>> > >> > strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
>> > >> > ' Remove trailing backslash.
>> > >> > strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) -
>> > >> > 1)
>> > >> >
>> > >> > ' Use the NameTranslate object to convert the NetBIOS name of the
>> > >> > group
>> > >> > ' to the Distinguished Name required for the LDAP provider.
>> > >> > objTrans.Init ADS_NAME_INITTYPE_DOMAIN, strNetBIOSDomain
>> > >> > objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
>> > >> > strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779)
>> > >> >
>> > >> > ' Bind to the group object.
>> > >> > Set objGroup = GetObject("LDAP://" & strGroupDN)
>> > >> >
>> > >> > ' Enumerate direct members of the group.
>> > >> > For Each objMember In objGroup.Members
>> > >> > ' Output Distinguished Name.
>> > >> > Wscript.Echo "DN: " & objMember.distinguishedName
>> > >> > ' Output Canonical Name.
>> > >> > objMember.GetInfoEx Array("canonicalName"), 0
>> > >> > arrNames = objMember.Get("canonicalName")
>> > >> > If (TypeName(arrNames) = "String") Then
>> > >> > Wscript.Echo " " & arrNames
>> > >> > ElseIf Not IsEmpty(arrNames) Then
>> > >> > For k = 0 To UBound(arrNames)
>> > >> > Wscript.Echo " " & arrNames(k)
>> > >> > Next
>> > >> > Else
>> > >> > Wscript.Echo " <no canonical name>"
>> > >> > End If
>> > >> > Next
>> > >> >
>> > >> > --
>> > >> > Richard
>> > >> > Microsoft MVP Scripting and ADSI
>> > >> > Hilltop Lab - http://www.rlmueller.net
>> > >
>



Re: CanonicalName Query by d_mc_alister

d_mc_alister
Mon Nov 13 03:15:51 CST 2006

Richard

Many Many Thanks. I didn't think I had to bind the other teams if I
didn't intend using them. Looking at it again I think I may have been
having a blonde moment. I've ammended it again and it works a treat!!!

Thanks Again

Des


Richard Mueller wrote:

> I believe you created a reference to TeamA, but not to TeamB and TeamC. You
> need to bind to objTeamB and objTeamC, similar to what you did for objTeamA.
> Since you did not bind objTeamB, the error is raised when you attempt to
> invoke a method of objTeamB, indicating that objTeamB must be an object
> created with a Set statement.
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
>
> <d_mc_alister@hotmail.com> wrote in message
> news:1163179865.588558.122920@e3g2000cwe.googlegroups.com...
> > Richard
> >
> > It would probably help if I show you the full text of the script
> >
> > Option Explicit
> >
> >
> > Dim objRootDSE, objTrans, strNetBIOSDomain, strNTName
> > Dim strGroupDN, strDNSDomain, objGroup, objMember, arrNames
> >
> >
> > ' Constants for NameTranslate object.
> > Const ADS_NAME_INITTYPE_DOMAIN = 1
> > Const ADS_NAME_TYPE_NT4 = 3
> > Const ADS_NAME_TYPE_1779 = 1
> >
> >
> > strNTName = InputBox("Enter NetBIOS name of group", "Find Members")
> >
> >
> > ' Determine DNS domain name from RootDSE object.
> > 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_TYPE_NT4, strDNSDomain
> > objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
> > strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
> > ' Remove trailing