Share via

Looking for a powershell script to export only specific distribution lists

Anonymous
2021-07-08T11:44:14+00:00

I have a csv file with displaynames of distribution lists.

I want to get a script which will take display names from this csv and give me output including SMTP address, aliases, group type.

Exchange online

I am using this > my CSV header is DisplayName.

$Groups = Import-Csv -Path D:\dls.csv

ForEach($DisplayName in $Groups){

#$DisplayName =$item.DispalyName

#$Identity = $DisplayName

}

Get-DistributionGroup $DisplayName.Displayname |select EmailAddresses,PrimarysmtpAddress,GroupType,Alias,RecipientType,DisplayName | Export-Csv -path D:\DLsmtp.csv -NoTypeInformation

The out has just one DL with details while input file has three...It only goes for one item or Row...the last row only

Microsoft 365 and Office | Subscription, account, billing | For business | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2021-07-15T06:09:45+00:00

    HI Pasha.

    Greetings.

    Sorry for the late reply, I figured it was ok to give a PowerShell cmdlet that shows a wider range.

    That being said, do still need help with it?

    Regards,

    Mac

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2021-07-08T13:27:58+00:00

    Hi Mac,

    The script is really good. But Can we change #Get All Distribution Groups to take Input only from a csv file with some specific Dls Not All? This is my requirement here.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2021-07-08T13:11:25+00:00

    HI Pasha.

    Greetings.

    Thank you for raising your concern in this community.

    If you have a c:\scripts folder

    Place this script and run it if you don’t have one, please create it.

    Make sure that the CSV file is edited accordingly.

    Make sure to check if the file is unblocked to prevent any errors when running the script.

    CSV file export path

    $Csvfile = "C:\scripts\ExportDGs.csv"

    Get all distribution groups

    $Groups = Get-DistributionGroup -ResultSize Unlimited

    Loop through distribution groups

    $Groups | ForEach-Object {

    $Group = $_.Name
        $DisplayName = $_.DisplayName
        $PrimarySmtpAddress = $_.PrimarySmtpAddress
        $GroupType = $_.GroupType
        $RecipientType = $_.RecipientType
        $Members = Get-DistributionGroupMember $group
        $ManagedBy = $_.ManagedBy
        $Alias = $_.Alias
        $HiddenFromAddressLists = $_.HiddenFromAddressListsEnabled
        $MemberJoinRestriction = $_.MemberJoinRestriction
        $MemberDepartRestriction = $_.MemberDepartRestriction
        $RequireSenderAuthenticationEnabled = $_.RequireSenderAuthenticationEnabled
        $AcceptMessagesOnlyFrom = $_.AcceptMessagesOnlyFrom
        $GrantSendOnBehalfTo = $_.GrantSendOnBehalfTo

    Create objects

        [PSCustomObject]@{
            Name                               = $Group
            DisplayName                        = $DisplayName
            PrimarySmtpAddress                 = $PrimarySmtpAddress
            Alias                              = $Alias
            GroupType                          = $GroupType
            RecipientType                      = $RecipientType
            Members                            = ($Members.Name -join ',')
            MembersPrimarySmtpAddress          = ($Members.PrimarySmtpAddress -join ',')
            ManagedBy                          = $ManagedBy.Name
            HiddenFromAddressLists             = $HiddenFromAddressLists
            MemberJoinRestriction              = $MemberJoinRestriction
            MemberDepartRestriction            = $MemberDepartRestriction
            RequireSenderAuthenticationEnabled = $RequireSenderAuthenticationEnabled
            AcceptMessagesOnlyFrom             = ($AcceptMessagesOnlyFrom.Name -join ',')
            GrantSendOnBehalfTo                = $GrantSendOnBehalfTo.Name
        }

    Export report to CSV file

    } | Export-CSV -Path $Csvfile -NoTypeInformation -Encoding UTF8 #-Delimiter ";"

    I will be waiting for your feedback.

    Regards,

    Mac

    Was this answer helpful?

    0 comments No comments