?
Solved

Find just the users without a mailbox in all groups in the domain and list the name and group name in a csv file.

Posted on 2008-10-17
33
Medium Priority
?
340 Views
Last Modified: 2012-08-13
Hi,

Find just the users without a mailbox in all groups in the domain and list the name and group name in a csv file.
So i can validate the requirment for this and remove unwanted users.

Regards
Sharath
0
Comment
Question by:bsharath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 20
  • 12
33 Comments
 
LVL 18

Expert Comment

by:exx1976
ID: 22744372
Finding all the users without email is easy enough, but what do you mean by list name and "Group name"?  What group name?  What group?
0
 
LVL 11

Author Comment

by:bsharath
ID: 22747504
There are times when we end up adding users into distribution groups without a Mailbox. Which is of no use. Users without mailbox who are in groups as Distribution is not required as they dont receive any mails.

I want to find users as such with the group names they are in. To validate before removing them...
0
 
LVL 11

Author Comment

by:bsharath
ID: 22747505
There are times when we end up adding users into distribution groups without a Mailbox. Which is of no use. Users without mailbox who are in groups as Distribution is not required as they dont receive any mails.

I want to find users as such with the group names they are in. To validate before removing them...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Expert Comment

by:AmazingTech
ID: 22774053
OK. Try this one out.

OU of users without email address. Check all groups and nested groups display only when a group or nested group is a distribution group.
Const ADS_GROUP_TYPE_LOCAL_GROUP = &h4
Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
Const ADS_GROUP_TYPE_UNIVERSAL_GROUP = &h8
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
 
Const E_ADS_PROPERTY_NOT_FOUND = &H8000500D
Const ForWriting = 2
CSVFile = "C:\OUUserGroupMembershipNoEmail.csv"
OUToSearch = "cn=users,dc=domain,dc=com"
 
On Error Resume Next
 
Set objDict = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objCSVFile = objFSO.OpenTextFile(CSVFile, ForWriting, True)
 
Set objOU = GetObject _
    ("LDAP://" + OUToSearch)
  
objOU.Filter = Array("User")
 
 
For Each objOUUser In objOU
If objOUUser.Mail = "" Then
    strUserName = objOUUser.sAMAccountName
    arrMembersOf = objOUUser.GetEx("memberOf")
  
    If Err.Number <>  E_ADS_PROPERTY_NOT_FOUND Then
        For Each strMemberOf in arrMembersOf
            WScript.Echo vbTab & strMemberOf
 
            Set objMemberOf = GetObject _
                ("LDAP://" & strMemberOf)
            objMemberOf.GetInfo
 
            strGroupList = UserNestedGroup(strMemberOf, chr(34) + objMemberOf.sAMAccountName + chr(34), FALSE)
        Next
    Else
        WScript.Echo vbTab & "memberOf attribute is not set"
        Err.Clear
    End If
    Wscript.Echo     
end if
Next
 
For Each User In objDict.Keys
    arrMultipleGroups = split(objDict(User),"#")
    For Each GroupMembership in arrMultipleGroups
        objCSVFile.WriteLine Chr(34) & User & Chr(34) & "," & GroupMembership
    Next
Next
 
Set objFSO = Nothing
objCSVFile.Close
 
wscript.echo
 
Function UserNestedGroup(strGroup, ParentGroup, DistributionGroup)
On Error Resume Next
    Set objGroup = GetObject _
        ("LDAP://" & strGroup)
    objGroup.GetInfo
 
    select case objgroup.grouptype
        Case ADS_GROUP_TYPE_LOCAL_GROUP
            wscript.echo "Domain Local Distribution Group"
            DistributionGroup = TRUE
        case ADS_GROUP_TYPE_LOCAL_GROUP Or ADS_GROUP_TYPE_SECURITY_ENABLED
            wscript.echo "Domain Local Security Group"
        case ADS_GROUP_TYPE_GLOBAL_GROUP
            wscript.echo "Domain Global Distribution Group"
            DistributionGroup = TRUE
        case ADS_GROUP_TYPE_GLOBAL_GROUP Or ADS_GROUP_TYPE_SECURITY_ENABLED
            wscript.echo "Domain Global Security Group"
        case ADS_GROUP_TYPE_UNIVERSAL_GROUP
            wscript.echo "Domain Universal Distribution Group"
            DistributionGroup = TRUE
        case ADS_GROUP_TYPE_UNIVERSAL_GROUP Or ADS_GROUP_TYPE_SECURITY_ENABLED
            wscript.echo "Domain Universal Security Group"
    end select
 
    PGroup = objGroup.sAMAccountName
    arrGroupMembersOf = objGroup.GetEx("memberOf")
 
    If Err.Number <> E_ADS_PROPERTY_NOT_FOUND Then
        PG = ParentGroup
 
        For Each strMemberOf In arrGroupMembersOf
            ParentGroup = PG
 
            Set objMemberOf = GetObject _
                ("LDAP://" & strMemberOf)
            objMemberOf.GetInfo
 
            If Instr(1,LookForGroup,objMemberOf.CN,vbtextcompare) <> 0 Then DistributionGroup = TRUE
 
            IF instr(1, ParentGroup, PGroup, vbtextcompare) <> 0 then
                ParentGroup = UserNestedGroup(strMemberOf, ParentGroup, DistributionGroup)
            ELSE
                ParentGroup = UserNestedGroup(strMemberOf, ParentGroup + "," + Chr(34) & PGroup & Chr(34), DistributionGroup)
            End If
        Next
    Else
        IF instr(1, ParentGroup, PGroup, vbtextcompare) = 0 then ParentGroup = ParentGroup + "," + Chr(34) & PGroup & Chr(34)
        If DistributionGroup Then
            If objDict.Exists(strUserName) Then
                objDict.Item(strUserName) = ParentGroup & "#" & objDict.Item(strUserName)
            Else
                objDict.Add strUserName, ParentGroup
            End If
        End If
    End If
    UserNestedGroup = ParentGroup
 
End Function

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22774147
AT
Is this the only line i need to change
OUToSearch = "cn=users,dc=domain,dc=com"

Show the path where all users are there?
Like
OUToSearch = "OU=countries,Ou=India,dc=domain,dc=com"
0
 
LVL 11

Author Comment

by:bsharath
ID: 22774148
AT
Is this the only line i need to change
OUToSearch = "cn=users,dc=domain,dc=com"

Show the path where all users are there?
Like
OUToSearch = "OU=countries,Ou=India,dc=domain,dc=com"
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22774184
Yes.
0
 
LVL 11

Author Comment

by:bsharath
ID: 22774272
When i run just with that change no error but just the csv file is created empty...
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22774364
OK. Let's see all users with distribution groups.

Const ADS_GROUP_TYPE_LOCAL_GROUP = &h4
Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
Const ADS_GROUP_TYPE_UNIVERSAL_GROUP = &h8
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
 
Const E_ADS_PROPERTY_NOT_FOUND = &H8000500D
Const ForWriting = 2
CSVFile = "C:\OUUserGroupMembershipNoEmail.csv"
OUToSearch = "OU=countries,Ou=India,dc=domain,dc=com"
 
On Error Resume Next
 
Set objDict = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objCSVFile = objFSO.OpenTextFile(CSVFile, ForWriting, True)
 
Set objOU = GetObject _
    ("LDAP://" + OUToSearch)
  
objOU.Filter = Array("User")
 
 
For Each objOUUser In objOU
'If objOUUser.Mail = "" Then
    strUserName = objOUUser.sAMAccountName
    arrMembersOf = objOUUser.GetEx("memberOf")
  
    If Err.Number <>  E_ADS_PROPERTY_NOT_FOUND Then
        For Each strMemberOf in arrMembersOf
            WScript.Echo vbTab & strMemberOf
 
            Set objMemberOf = GetObject _
                ("LDAP://" & strMemberOf)
            objMemberOf.GetInfo
 
            strGroupList = UserNestedGroup(strMemberOf, chr(34) + objMemberOf.sAMAccountName + chr(34), FALSE)
        Next
    Else
        WScript.Echo vbTab & "memberOf attribute is not set"
        Err.Clear
    End If
    Wscript.Echo     
'end if
Next
 
For Each User In objDict.Keys
    arrMultipleGroups = split(objDict(User),"#")
    For Each GroupMembership in arrMultipleGroups
        objCSVFile.WriteLine Chr(34) & User & Chr(34) & "," & GroupMembership
    Next
Next
 
Set objFSO = Nothing
objCSVFile.Close
 
wscript.echo
 
Function UserNestedGroup(strGroup, ParentGroup, DistributionGroup)
On Error Resume Next
    Set objGroup = GetObject _
        ("LDAP://" & strGroup)
    objGroup.GetInfo
 
    select case objgroup.grouptype
        Case ADS_GROUP_TYPE_LOCAL_GROUP
            wscript.echo "Domain Local Distribution Group"
            DistributionGroup = TRUE
        case ADS_GROUP_TYPE_LOCAL_GROUP Or ADS_GROUP_TYPE_SECURITY_ENABLED
            wscript.echo "Domain Local Security Group"
        case ADS_GROUP_TYPE_GLOBAL_GROUP
            wscript.echo "Domain Global Distribution Group"
            DistributionGroup = TRUE
        case ADS_GROUP_TYPE_GLOBAL_GROUP Or ADS_GROUP_TYPE_SECURITY_ENABLED
            wscript.echo "Domain Global Security Group"
        case ADS_GROUP_TYPE_UNIVERSAL_GROUP
            wscript.echo "Domain Universal Distribution Group"
            DistributionGroup = TRUE
        case ADS_GROUP_TYPE_UNIVERSAL_GROUP Or ADS_GROUP_TYPE_SECURITY_ENABLED
            wscript.echo "Domain Universal Security Group"
    end select
 
    PGroup = objGroup.sAMAccountName
    arrGroupMembersOf = objGroup.GetEx("memberOf")
 
    If Err.Number <> E_ADS_PROPERTY_NOT_FOUND Then
        PG = ParentGroup
 
        For Each strMemberOf In arrGroupMembersOf
            ParentGroup = PG
 
            Set objMemberOf = GetObject _
                ("LDAP://" & strMemberOf)
            objMemberOf.GetInfo
 
            If Instr(1,LookForGroup,objMemberOf.CN,vbtextcompare) <> 0 Then DistributionGroup = TRUE
 
            IF instr(1, ParentGroup, PGroup, vbtextcompare) <> 0 then
                ParentGroup = UserNestedGroup(strMemberOf, ParentGroup, DistributionGroup)
            ELSE
                ParentGroup = UserNestedGroup(strMemberOf, ParentGroup + "," + Chr(34) & PGroup & Chr(34), DistributionGroup)
            End If
        Next
    Else
        IF instr(1, ParentGroup, PGroup, vbtextcompare) = 0 then ParentGroup = ParentGroup + "," + Chr(34) & PGroup & Chr(34)
        If DistributionGroup Then
            If objDict.Exists(strUserName) Then
                objDict.Item(strUserName) = ParentGroup & "#" & objDict.Item(strUserName)
            Else
                objDict.Add strUserName, ParentGroup
            End If
        End If
    End If
    UserNestedGroup = ParentGroup
 
End Function

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22774684
After a long query time i get 3 blank boxes without any message and it closed. No data in the created csv
0
 
LVL 11

Author Comment

by:bsharath
ID: 22774685
After a long query time i get 3 blank boxes without any message and it closed. No data in the created csv
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22776921
OK. Let's see if the groups are coming in.

I also see 1 other line that can be deleted.

Does the screen show anything when you run this?
Const ADS_GROUP_TYPE_LOCAL_GROUP = &h4
Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
Const ADS_GROUP_TYPE_UNIVERSAL_GROUP = &h8
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
 
Const E_ADS_PROPERTY_NOT_FOUND = &H8000500D
Const ForWriting = 2
CSVFile = "C:\OUUserGroupMembershipNoEmail.csv"
OUToSearch = "OU=countries,Ou=India,dc=domain,dc=com"
 
On Error Resume Next
 
Set objDict = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objCSVFile = objFSO.OpenTextFile(CSVFile, ForWriting, True)
 
Set objOU = GetObject _
    ("LDAP://" + OUToSearch)
  
objOU.Filter = Array("User")
 
 
For Each objOUUser In objOU
'If objOUUser.Mail = "" Then
    strUserName = objOUUser.sAMAccountName
    arrMembersOf = objOUUser.GetEx("memberOf")
  
    If Err.Number <>  E_ADS_PROPERTY_NOT_FOUND Then
        For Each strMemberOf in arrMembersOf
            WScript.Echo vbTab & strMemberOf
 
            Set objMemberOf = GetObject _
                ("LDAP://" & strMemberOf)
            objMemberOf.GetInfo
 
            strGroupList = UserNestedGroup(strMemberOf, chr(34) + objMemberOf.sAMAccountName + chr(34), TRUE)
        Next
    Else
        WScript.Echo vbTab & "memberOf attribute is not set"
        Err.Clear
    End If
    Wscript.Echo     
'end if
Next
 
For Each User In objDict.Keys
    arrMultipleGroups = split(objDict(User),"#")
    For Each GroupMembership in arrMultipleGroups
        objCSVFile.WriteLine Chr(34) & User & Chr(34) & "," & GroupMembership
    Next
Next
 
Set objFSO = Nothing
objCSVFile.Close
 
wscript.echo
 
Function UserNestedGroup(strGroup, ParentGroup, DistributionGroup)
On Error Resume Next
    Set objGroup = GetObject _
        ("LDAP://" & strGroup)
    objGroup.GetInfo
 
    select case objgroup.grouptype
        Case ADS_GROUP_TYPE_LOCAL_GROUP
            wscript.echo "Domain Local Distribution Group"
            DistributionGroup = TRUE
        case ADS_GROUP_TYPE_LOCAL_GROUP Or ADS_GROUP_TYPE_SECURITY_ENABLED
            wscript.echo "Domain Local Security Group"
        case ADS_GROUP_TYPE_GLOBAL_GROUP
            wscript.echo "Domain Global Distribution Group"
            DistributionGroup = TRUE
        case ADS_GROUP_TYPE_GLOBAL_GROUP Or ADS_GROUP_TYPE_SECURITY_ENABLED
            wscript.echo "Domain Global Security Group"
        case ADS_GROUP_TYPE_UNIVERSAL_GROUP
            wscript.echo "Domain Universal Distribution Group"
            DistributionGroup = TRUE
        case ADS_GROUP_TYPE_UNIVERSAL_GROUP Or ADS_GROUP_TYPE_SECURITY_ENABLED
            wscript.echo "Domain Universal Security Group"
    end select
 
    PGroup = objGroup.sAMAccountName
    arrGroupMembersOf = objGroup.GetEx("memberOf")
 
    If Err.Number <> E_ADS_PROPERTY_NOT_FOUND Then
        PG = ParentGroup
 
        For Each strMemberOf In arrGroupMembersOf
            ParentGroup = PG
 
            Set objMemberOf = GetObject _
                ("LDAP://" & strMemberOf)
            objMemberOf.GetInfo
 
            IF instr(1, ParentGroup, PGroup, vbtextcompare) <> 0 then
                ParentGroup = UserNestedGroup(strMemberOf, ParentGroup, DistributionGroup)
            ELSE
                ParentGroup = UserNestedGroup(strMemberOf, ParentGroup + "," + Chr(34) & PGroup & Chr(34), DistributionGroup)
            End If
        Next
    Else
        IF instr(1, ParentGroup, PGroup, vbtextcompare) = 0 then ParentGroup = ParentGroup + "," + Chr(34) & PGroup & Chr(34)
        If DistributionGroup Then
            If objDict.Exists(strUserName) Then
                objDict.Item(strUserName) = ParentGroup & "#" & objDict.Item(strUserName)
            Else
                objDict.Add strUserName, ParentGroup
            End If
        End If
    End If
    UserNestedGroup = ParentGroup
 
End Function

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22776964
Still the same AT 3 blank boxes and no data within the csv...
0
 
LVL 11

Author Comment

by:bsharath
ID: 22776965
Still the same AT 3 blank boxes and no data within the csv...
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22783491
Is this the proper OU?

OUToSearch = "OU=countries,Ou=India,dc=domain,dc=com"

Or should it be this?

OUToSearch = "OU=India,OU=countries,dc=domain,dc=com"

And your domain is domain.com?
0
 
LVL 11

Author Comment

by:bsharath
ID: 22783884
I tried in both ways still no results...

When i go to the OU Properties > Objects i get this

Development.Group.co.uk/Countries/IND/User Accounts/Named Accounts
Now how should i mention this path.
Its a User create OU structure...
0
 
LVL 11

Author Comment

by:bsharath
ID: 22783885
I tried in both ways still no results...

When i go to the OU Properties > Objects i get this

Development.Group.co.uk/Countries/IND/User Accounts/Named Accounts
Now how should i mention this path.
Its a User create OU structure...
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22786543
Hmm...

Try this.

OUToSearch = "OU=Named Accounts,OU=User Accounts,OU=Ind,OU=countries,dc=Development,dc=Group,dc=co,dc=uk"
0
 
LVL 11

Author Comment

by:bsharath
ID: 22786649
For many i get this

---------------------------
Windows Script Host
---------------------------
      memberOf attribute is not set
---------------------------
OK  
---------------------------

But data is into the csv...

What does the Colum A,B,C data mean...
0
 
LVL 11

Author Comment

by:bsharath
ID: 22786650
For many i get this

---------------------------
Windows Script Host
---------------------------
      memberOf attribute is not set
---------------------------
OK  
---------------------------

But data is into the csv...

What does the Colum A,B,C data mean...
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22787035
Yes. That is normal. When a group is not nested into another group I'm echoing this message. I could remove it.
0
 
LVL 11

Author Comment

by:bsharath
ID: 22787055
Can you remove it and what are the data in A,B,C colums
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22787157
A = Username
B = User has direct membership
C = B is nested into here
D = C is nested into here

Any column B to end can be the distribution group.
Const ADS_GROUP_TYPE_LOCAL_GROUP = &h4
Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
Const ADS_GROUP_TYPE_UNIVERSAL_GROUP = &h8
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
 
Const E_ADS_PROPERTY_NOT_FOUND = &H8000500D
Const ForWriting = 2
CSVFile = "C:\OUUserGroupMembershipNoEmail.csv"
OUToSearch = "OU=Named Accounts,OU=User Accounts,OU=Ind,OU=countries,dc=Development,dc=Group,dc=co,dc=uk"
 
On Error Resume Next
 
Set objDict = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objCSVFile = objFSO.OpenTextFile(CSVFile, ForWriting, True)
 
Set objOU = GetObject _
    ("LDAP://" + OUToSearch)
  
objOU.Filter = Array("User")
 
 
For Each objOUUser In objOU
If objOUUser.Mail = "" Then
    strUserName = objOUUser.sAMAccountName
    arrMembersOf = objOUUser.GetEx("memberOf")
  
    If Err.Number <>  E_ADS_PROPERTY_NOT_FOUND Then
        For Each strMemberOf in arrMembersOf
            WScript.Echo vbTab & strMemberOf
 
            Set objMemberOf = GetObject _
                ("LDAP://" & strMemberOf)
            objMemberOf.GetInfo
 
            strGroupList = UserNestedGroup(strMemberOf, chr(34) + objMemberOf.sAMAccountName + chr(34), FALSE)
        Next
    Else
        Err.Clear
    End If
    Wscript.Echo     
end if
Next
 
For Each User In objDict.Keys
    arrMultipleGroups = split(objDict(User),"#")
    For Each GroupMembership in arrMultipleGroups
        objCSVFile.WriteLine Chr(34) & User & Chr(34) & "," & GroupMembership
    Next
Next
 
Set objFSO = Nothing
objCSVFile.Close
 
wscript.echo
 
Function UserNestedGroup(strGroup, ParentGroup, DistributionGroup)
On Error Resume Next
    Set objGroup = GetObject _
        ("LDAP://" & strGroup)
    objGroup.GetInfo
 
    select case objgroup.grouptype
        Case ADS_GROUP_TYPE_LOCAL_GROUP
            wscript.echo "Domain Local Distribution Group"
            DistributionGroup = TRUE
        case ADS_GROUP_TYPE_LOCAL_GROUP Or ADS_GROUP_TYPE_SECURITY_ENABLED
            wscript.echo "Domain Local Security Group"
        case ADS_GROUP_TYPE_GLOBAL_GROUP
            wscript.echo "Domain Global Distribution Group"
            DistributionGroup = TRUE
        case ADS_GROUP_TYPE_GLOBAL_GROUP Or ADS_GROUP_TYPE_SECURITY_ENABLED
            wscript.echo "Domain Global Security Group"
        case ADS_GROUP_TYPE_UNIVERSAL_GROUP
            wscript.echo "Domain Universal Distribution Group"
            DistributionGroup = TRUE
        case ADS_GROUP_TYPE_UNIVERSAL_GROUP Or ADS_GROUP_TYPE_SECURITY_ENABLED
            wscript.echo "Domain Universal Security Group"
    end select
 
    PGroup = objGroup.sAMAccountName
    arrGroupMembersOf = objGroup.GetEx("memberOf")
 
    If Err.Number <> E_ADS_PROPERTY_NOT_FOUND Then
        PG = ParentGroup
 
        For Each strMemberOf In arrGroupMembersOf
            ParentGroup = PG
 
            Set objMemberOf = GetObject _
                ("LDAP://" & strMemberOf)
            objMemberOf.GetInfo
 
            If Instr(1,LookForGroup,objMemberOf.CN,vbtextcompare) <> 0 Then DistributionGroup = TRUE
 
            IF instr(1, ParentGroup, PGroup, vbtextcompare) <> 0 then
                ParentGroup = UserNestedGroup(strMemberOf, ParentGroup, DistributionGroup)
            ELSE
                ParentGroup = UserNestedGroup(strMemberOf, ParentGroup + "," + Chr(34) & PGroup & Chr(34), DistributionGroup)
            End If
        Next
    Else
        IF instr(1, ParentGroup, PGroup, vbtextcompare) = 0 then ParentGroup = ParentGroup + "," + Chr(34) & PGroup & Chr(34)
        If DistributionGroup Then
            If objDict.Exists(strUserName) Then
                objDict.Item(strUserName) = ParentGroup & "#" & objDict.Item(strUserName)
            Else
                objDict.Add strUserName, ParentGroup
            End If
        End If
    End If
    UserNestedGroup = ParentGroup
 
End Function

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22787254
AT isn't this script to check if each user in the group has a mailbox or not?
And get just names of users who are in the group or nested group?

Is this for some other Q... of mine?
0
 
LVL 11

Author Comment

by:bsharath
ID: 22787255
AT isn't this script to check if each user in the group has a mailbox or not?
And get just names of users who are in the group or nested group?

Is this for some other Q... of mine?
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22787369
Yours. I was checking for the E-mail attribute was blank. I'm not too sure how to check if they have an exchange box.

If objOUUser.Mail = "" Then
0
 
LVL 11

Author Comment

by:bsharath
ID: 22788296
Ok in this case can we show a OU that has USers. As we can check an OU that has users with E-Mail attribute not a mailbox...

Any help with the other posts?
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22788513
You know what I've been trying to do the other post for a couple days now. I've been trying to reuse some functions from other posts I've done for getting nesting groups and it's not working like I want to. I think I'm going to scrap trying to reuse the code and create the function from scratch because I'm getting so confused with it
0
 
LVL 11

Author Comment

by:bsharath
ID: 22832537
Any view on this AT
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22833889
Sorry with the MS KB958644 I've been really busy at work trying to patch everything.
0
 
LVL 11

Author Comment

by:bsharath
ID: 22897329
Any help on this...
0
 
LVL 21

Accepted Solution

by:
AmazingTech earned 2000 total points
ID: 22928189
Was there still a problem with this one?

Try this.
Const ADS_GROUP_TYPE_LOCAL_GROUP = &h4
Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
Const ADS_GROUP_TYPE_UNIVERSAL_GROUP = &h8
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
 
Const ForWriting = 2
CSVFile = "C:\OUUserGroupMembershipNoEmail.csv"
OUToSearch = "OU=Named Accounts,OU=User Accounts,OU=Ind,OU=countries,dc=Development,dc=Group,dc=co,dc=uk"
 
On Error Resume Next
 
Set objDict = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objCSVFile = objFSO.OpenTextFile(CSVFile, ForWriting, True)
 
Set objOU = GetObject _
    ("LDAP://" + OUToSearch)
  
objOU.Filter = Array("User")
 
 
For Each objOUUser In objOU
If objOUUser.Mail = "" Then
    strUserName = objOUUser.sAMAccountName
    arrMembersOf = objOUUser.GetEx("memberOf")
  
    If isempty(arrMembersOf) Then
        Err.Clear
    Else
        For Each strMemberOf in arrMembersOf
            WScript.Echo vbTab & strMemberOf
 
            Set objMemberOf = GetObject _
                ("LDAP://" & strMemberOf)
            objMemberOf.GetInfo
 
            strGroupList = UserNestedGroup(strMemberOf, chr(34) + objMemberOf.sAMAccountName + chr(34), FALSE)
        Next
    End If
    Wscript.Echo     
end if
Next
 
For Each User In objDict.Keys
    arrMultipleGroups = split(objDict(User),"#")
    For Each GroupMembership in arrMultipleGroups
        objCSVFile.WriteLine Chr(34) & User & Chr(34) & "," & GroupMembership
    Next
Next
 
Set objFSO = Nothing
objCSVFile.Close
 
wscript.echo
 
Function UserNestedGroup(strGroup, ParentGroup, DistributionGroup)
On Error Resume Next
    Set objGroup = GetObject _
        ("LDAP://" & strGroup)
    objGroup.GetInfo
 
    select case objgroup.grouptype
        Case ADS_GROUP_TYPE_LOCAL_GROUP
            wscript.echo "Domain Local Distribution Group"
            DistributionGroup = TRUE
        case ADS_GROUP_TYPE_LOCAL_GROUP Or ADS_GROUP_TYPE_SECURITY_ENABLED
            wscript.echo "Domain Local Security Group"
        case ADS_GROUP_TYPE_GLOBAL_GROUP
            wscript.echo "Domain Global Distribution Group"
            DistributionGroup = TRUE
        case ADS_GROUP_TYPE_GLOBAL_GROUP Or ADS_GROUP_TYPE_SECURITY_ENABLED
            wscript.echo "Domain Global Security Group"
        case ADS_GROUP_TYPE_UNIVERSAL_GROUP
            wscript.echo "Domain Universal Distribution Group"
            DistributionGroup = TRUE
        case ADS_GROUP_TYPE_UNIVERSAL_GROUP Or ADS_GROUP_TYPE_SECURITY_ENABLED
            wscript.echo "Domain Universal Security Group"
    end select
 
    PGroup = objGroup.sAMAccountName
    arrGroupMembersOf = objGroup.GetEx("memberOf")
 
    If isempty(arrGroupMemersOf) Then
        IF instr(1, ParentGroup, PGroup, vbtextcompare) = 0 then ParentGroup = ParentGroup + "," + Chr(34) & PGroup & Chr(34)
        If DistributionGroup Then
            If objDict.Exists(strUserName) Then
                objDict.Item(strUserName) = ParentGroup & "#" & objDict.Item(strUserName)
            Else
                objDict.Add strUserName, ParentGroup
            End If
        End If
    Else
        PG = ParentGroup
 
        For Each strMemberOf In arrGroupMembersOf
            ParentGroup = PG
 
            Set objMemberOf = GetObject _
                ("LDAP://" & strMemberOf)
            objMemberOf.GetInfo
 
            If Instr(1,LookForGroup,objMemberOf.CN,vbtextcompare) <> 0 Then DistributionGroup = TRUE
 
            IF instr(1, ParentGroup, PGroup, vbtextcompare) <> 0 then
                ParentGroup = UserNestedGroup(strMemberOf, ParentGroup, DistributionGroup)
            ELSE
                ParentGroup = UserNestedGroup(strMemberOf, ParentGroup + "," + Chr(34) & PGroup & Chr(34), DistributionGroup)
            End If
        Next
 
    End If
    UserNestedGroup = ParentGroup
 
End Function

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 22928317
Thanks a lot AT worked perfect...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question