Query distribution list from CSV file using EMS
I have a csv file with heading.
Alias Email
User1
User1@domain.com
User2
User2@domain.com
I would like to run this cmdlet to query the distribution which these user belong to:
Get-DistributionGroup | where { (Get-DistributionGroupMember $_ | foreach {$_.PrimarySmtpAddress}) -contains "$_.email" }
$_.email will take the email address from csv file.
I tried this cmdlet but failed.
Please help
November 9th, 2010 1:23am
On Tue, 9 Nov 2010 06:18:14 +0000, Suriya25 wrote:
>
>
>I have a csv file with heading.
>
>Alias Email
>
>User1 User1@domain.com
>
>User2 User2@domain.com
>
>I would like to run this cmdlet to query the distribution which these user belong to:
>
>
>
>Get-DistributionGroup | where { (Get-DistributionGroupMember $_ | foreach {$_.PrimarySmtpAddress}) -contains "$_.email" }
>
>$_.email will take the email address from csv file.
>
>I tried this cmdlet but failed.
You're trying to use the "$_" to represent the distribution list
member and there's no "email" property in those objects.
Try something like this:
import-csv ... | foreach {$e = $_.email; get-distributiongroup | ...
-contains $e}
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
November 9th, 2010 10:49pm
And you can export the results to the txt file:
import-csv ... | foreach {$e = $_.email; get-distributiongroup | ...
-contains $e} | select $e,name >>c:\group.txt}Frank Wang
November 11th, 2010 3:38am
I used this and it is work:
$user = Import-Csv c:\ps\disable.csv
Get-DistributionGroup | where { (Get-DistributionGroupMember $_ | foreach {$_.PrimarySmtpAddress}) -contains $User.smtp}
Free Windows Admin Tool Kit Click here and download it now
November 11th, 2010 11:05pm