Created
September 19, 2016 03:42
-
-
Save chrisbrownie/3564ee0bb0eb1ba05921153a7f1ad664 to your computer and use it in GitHub Desktop.
Returns all mail-enabled groups in the domain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'====================================================================== | |
' GetDistributionGroups.vbs | |
'====================================================================== | |
' Author: Chris Brown ([email protected]) | |
' Date: 09/10/2014 | |
' Details: Returns all mail-enabled groups in the domain | |
' Source: Unknown (I forget if I wrote this myself or found it somewhere) | |
'====================================================================== | |
' Everything below this will be searched. Must be in the format | |
' of an LDAP DinguishedName | |
TopLevelDN = "DC=BlueYonderAirlines,DC=com" | |
' Do not modify below this line | |
'====================================================================== | |
' Spit out the CSV headers | |
Wscript.Echo "TopLevelDN;DistinguishedName;DisplayName;mail;mailnickname;grouptype" | |
' Get the top level OU's contents | |
Set OU = GetObject ("LDAP://" & TopLevelDN) | |
GetDistributionGroupsInOU (OU) | |
Sub GetDistributionGroupsInOU (OU) | |
For Each childObject in OU | |
Select Case childObject.Class | |
Case "group" | |
' It's a group | |
If Not childObject.mailnickname = "" Then | |
' Group is mail enabled (mailNickname is not empty) | |
Wscript.Echo TopLevelDN & ";" & childObject.DistinguishedName & ";" & childObject.DisplayName & ";" & childObject.mail & ";" & childObject.mailNickname & ";" & childObject.grouptype & ";" | |
End If ' not mailnickname = "" | |
Case "organizationalUnit","container" | |
' It's an OU/container, run this sub again | |
GetDistributionGroupsInOU(childObject) | |
End Select 'childObject.class | |
Next ' childObject | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment