MAILING DGs
Hello,
I use Exchange 2007 and I would like to send a mailing to the Exchange users about the groups they are belonging to.
I use the shell command (at the end) to know which DGs a user belongs but for the mailing I would need the data as is:
IDENTITY;NAME;PRIMARY1;SMTPADDRESS1;PRIMARY2;SMTPADDRESS2;PRIMARY3;SMTPADDRESS3;
GRAIG;DG001;DG001@company.com;DG002;DG002@company.com;DG003;DG003@company.com
Shell command:
foreach ($dg in get-distributiongroup -resultsize unlimited) {if ((get-distributiongroupmember $dg |% {$_.samaccountname}) -contains "GRAIG") {$dg | select name,primarysmtpaddress}}
Result:
Name
PrimarySmtpAddress
----
------------------
DG001
DG001@company.com
DG002
DG002@company.com
DG003
DG003@company.com
Would you know how to get that result?
Thanks,
Graig
August 14th, 2012 6:26am
How to Export all distribution Group and All members of it (Exchange 2007 & Exchange 2010)
http://careexchange.in/how-to-export-all-distribution-group-and-all-members-of-it-exchange-2010/Satheshwaran Manoharan | Exchange 2003/2007/2010 | Blog:http://www.careexchange.in | Please mark it as an answer if it really helps you
Free Windows Admin Tool Kit Click here and download it now
August 14th, 2012 5:41pm
Hi
How is the result like that
foreach ($dg in get-distributiongroup -resultsize unlimited) {if ((get-distributiongroupmember $dg |% {$_.samaccountname}) -contains "GRAIG") {$dg | select name,primarysmtpaddress | Format-Table -HideTableHeaders -AutoSize}}
CheersZi Feng
TechNet Community Support
August 15th, 2012 5:59am
I seems like it it what I am looking for :-D
However I cannot run the ps1 file I get the following error message:
Unexpected token 'Report' in expression or statement.
At C:\1.ps1:5 char:45
+ $Groups| foreach{ $GroupName=$_.Name $Report= <<<< Get-distributionGroupMember -identity $_.identity| select @{Name='Distributi
on Group'; Expression={[String]::join(";", $GroupName)}}, Name, PrimarySmtpAddress $Reports=$Reports+$Report }
would you know how to fix that error??
Thanks
Free Windows Admin Tool Kit Click here and download it now
August 15th, 2012 2:34pm
Thanks Zi,
But it is not what I am looking for. I need to also have the user appearing in the result and need to check not 1 user but all of them.
Graig
August 15th, 2012 2:35pm
You can Take the Script .
Run Line by line
That should help.
i guess , while Copying its missing out some space or something
Satheshwaran Manoharan | Exchange 2003/2007/2010 | Blog:http://www.careexchange.in | Please mark it as an answer if it really helps you
Free Windows Admin Tool Kit Click here and download it now
August 15th, 2012 2:42pm
On Wed, 15 Aug 2012 18:31:20 +0000, Graiggoriz wrote:
>
>
>I seems like it it what I am looking for :-D
>
>However I cannot run the ps1 file I get the following error message:
>
>Unexpected token 'Report' in expression or statement. At C:\1.ps1:5 char:45 + $Groups| foreach{ $GroupName=$_.Name $Report= <<<< Get-distributionGroupMember -identity $_.identity| select @{Name='Distributi on Group'; Expression={[String]::join(";", $GroupName)}},
Name, PrimarySmtpAddress $Reports=$Reports+$Report }
>
>would you know how to fix that error??
It's missing the semicolon after "foreach{ $GroupName=$_.Name".
It's also missing the semicolon after "PrimarySmtpAddress".
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
August 15th, 2012 3:45pm
$Groups=Get-DistributionGroup
$Groups| foreach{
$GroupName=$_.Name
$Report+=Get-distributionGroupMember -identity $_.identity| select @{Name='Distribution Group'; Expression={[String]::join(";", $GroupName)}}, Name, PrimarySmtpAddress}
$Report| export-csv "c:\MyFile.csv" -notype
Works like a Charm - Written by Evan Liu
http://social.technet.microsoft.com/Forums/nl/exchangesvradmin/thread/1fff966d-a643-4935-b18b-146110729c63Satheshwaran Manoharan | Exchange 2003/2007/2010 | Blog:http://www.careexchange.in | Please mark it as an answer if it really helps you
Free Windows Admin Tool Kit Click here and download it now
August 15th, 2012 5:49pm
$Groups=Get-DistributionGroup
$Groups| foreach{
$GroupName=$_.Name
$Report+=Get-distributionGroupMember -identity $_.identity| select @{Name='Distribution Group'; Expression={[String]::join(";", $GroupName)}}, Name, PrimarySmtpAddress}
$Report| export-csv "c:\MyFile.csv" -notype
Works like a Charm - Written by Evan Liu
http://social.technet.microsoft.com/Forums/nl/exchangesvradmin/thread/1fff966d-a643-4935-b18b-146110729c63Satheshwaran Manoharan | Exchange 2003/2007/2010 | Blog:http://www.careexchange.in | Please mark it as an answer if it really helps you
August 15th, 2012 5:53pm
Thanks,
I copy paste the one from
Satheshwaran Manoharan and it runs but I get the below error message:
Method invocation failed because [System.Management.Automation.PSObject] doesn't contain a method named 'op_Addition'.
At C:\file.ps1:7 char:10
+ $Report+=G <<<< et-distributionGroupMember -identity $_.identity| select @{Name='Distribution Group'; Expression={[String]::join(";", $GroupName)}}, Name, PrimarySmtpAddress}
Anyone can help me with that?
Graig
Free Windows Admin Tool Kit Click here and download it now
August 16th, 2012 3:00am
The second code on the Thread works:
$Reports=@()
$Groups=Get-DistributionGroup
$Groups| foreach{
$GroupName=$_.Name
$Report=Get-distributionGroupMember -identity $_.identity| select @{Name='Distribution Group'; Expression={[String]::join(";", $GroupName)}}, Name, PrimarySmtpAddress
$Reports=$Reports+$Report
}
$Reports| out-file "c:\MyFile2.txt"
Many Thanks!
August 16th, 2012 8:37am