Recurse DL Parents

I am working on a project to add members to a series of distribution lists. These lists are nested into various parent lists, sometimes 2-3 layers deep. It's never been updated, but almost all these distribution groups are Mail-enabled Global Security groups. Powershell really, really wants to work with Universal groups. You can't just convert the current DL to Universal, it's parent needs to be Universal also.

The following function recurses a DL's parents and converts them all to Universal DLs using Quest's Set-QADGroup.

function Find-ParentDL ($dl) {
        $MyDL = Get-QADGroup $dl
               
        if ($myDL.memberof -ne $null -and $myDL.groupscope -eq "Global") {
                foreach ($m in $myDL.Memberof) {
                        find-parentDL $m
                }
        }
        if ($dl -ne "" -and $myDL.groupscope -eq "Global") {Set-qadgroup -GroupScope Universal -Identity $dl}

        #       If you want to return the DL structure.
        #       $arr = New-Object system.Object
        #       $arr | Add-Member -memberType NoteProperty -name Members -value $dl
        #       return $arr
}

#Call by running:
Find-Parent "Example All Users List"

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <blockquote> <center> <hr> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <drupal6>, <html>, <java>, <javascript>, <php>, <posh>.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.