Get List of Users From Csv With List of Dls

Header in the csv file should be DL

$PathToCsv = "groups.csv"

Import-Csv $PathToCsv |
    ForEach-Object {

        $group = $null

        $group = $_.DL
        Get-ADGroupMember $group |
            Select-Object samaccountname |
            ForEach-Object {

                New-Object psobject -Property @{
                    DL = $group
                    UserName = $_.samaccountname
                }
            }
    } |
    Export-Csv -NoTypeInformation "output.csv"

See also