Forum Discussion
Exchange Online Quick Tip: Export all distribution lists with members to a CSV file!
- gymivAug 16, 2024Copper Contributor
When I run the script I get the below error. Can you assist.
$username = "username@domain"
$password = Get-Content "C:\test\test.txt" | ConvertTo-SecureString
$cred = New-Object system.management.automation.pscredential -ArgumentList $username, $password
Connect-ExchangeOnline -Credential $cred
Connect-MsolService -Credential $cred
$Company = Get-MsolCompanyInformation | select -exp DisplayName
$InitialDomain = Get-MsolCompanyInformation | select -exp InitialDomain
$host.ui.RawUI.WindowTitle = "You are connected to: " + $Company + " (" + $InitialDomain + ") "
$Result=@()
$groups = Get-DistributionGroup -resultsize Unlimited | fl PrimarySMTPAddress
$totalmbx = $groups.Count
$i = 1
$groups | ForEach-Object {
Write-Progress -activity "Processing $_.DisplayName" -status "$i out of $totalmbx completed"
$group = $_
$Result += New-Object PSObject -property @{
GroupName = $group.DisplayName
Member = $member.Name
EmailAddress = $member.PrimarySMTPAddress
RecipientType= $member.RecipientType
}}
$i++}
$Result | Export-CSV "C:\test\All-Distribution-Group-Members.csv" -NoTypeInformation
Get-DistributionGroupMember : Cannot bind argument to parameter 'Identity' because it is null.
At line:8 char:39
+ Get-DistributionGroupMember -Identity $group.Name -ResultSize Unlimit ...
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-DistributionGroupMember], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Get-DistributionGroupMember