lazywinadmin / lazywinadmin.github.io

Personal Blog - Using the minimal-mistakes jekyll template
https://lazywinadmin.com
MIT License
4 stars 3 forks source link

2015/08/powershello365-get-distribution-groups #277

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

PowerShell/Office 365 - Get the distribution groups membership - LazyWinAdmin

I was recently looking at Office365/Exchange Online to retrieve Distribution Group membership. This is pretty simple using something like: Get-DistributionGroupMember -Identity "Marketing"

https://lazywinadmin.github.io/2015/08/powershello365-get-distribution-groups.html

ImStillWorking commented 2 years ago

Can you provide additional code to export output results to an csv file. Thanks

lazywinadmin commented 2 years ago

@ImStillWorking You can just pipe the code to Export-CSV myfile.csv

(Get-DistributionGroup).identity | ForEach-Object{
    $DistributionGroupName = $_
    Get-DistributionGroupMember -Identity $_ | ForEach-Object{
        [PSCustomObject]@{
            DistributionGroup = $DistributionGroupName
            MemberName = $_.Name
            #Other recipient properties here
        }
    }
}| Export-CSV myfile.csv