Exchange PowerShell Script

Hi Experts,

Need a script that could do the following:

Scan all distribution groups and list all members email address that is not equal to that is associated to that distribution group.

Is this possible and how. Thanks in advance.


Who is Participating?
SeanConnect With a Mentor System EngineerCommented:
Try and run it without exporting to CSV first:


$Groups| foreach{


Get-distributionGroupMember -identity $_.identity| select @{Name='Distribution Group'; Expression={[String]::join(";", $GroupName)}}, Name, PrimarySmtpAddress}

let me know if it still errors out for you.
SeanSystem EngineerCommented:
Here is a script to get all groups and their members...if you play with it you could probably only get the members you want to but if you only need to run it once i would just use excel to remove the users you don't need.


$Groups| foreach{


$Report+=Get-distributionGroupMember -identity $_.identity| select @{Name='Distribution Group'; Expression={[String]::join(";", $GroupName)}}, Name, PrimarySmtpAddress}

$Report| export-csv "c:\MyFile.csv" -notype
introluxAuthor Commented:

Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null
At C:\test.ps1:5 char:20
+ $Report| export-csv <<<<  "c:\MyFile.csv" -notype
    + CategoryInfo          : InvalidData: (:) [Export-Csv], ParameterBindingV
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
introluxAuthor Commented:
That worked thanks!
introluxAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.