locked
MAILING DGs RRS feed

  • Question

  • 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

    Tuesday, August 14, 2012 10:17 AM

Answers

  • $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-146110729c63

    Satheshwaran Manoharan | Exchange 2003/2007/2010 | Blog:http://www.careexchange.in | Please mark it as an answer if it really helps you

    • Marked as answer by Graiggoriz Thursday, August 16, 2012 12:34 PM
    Wednesday, August 15, 2012 9:49 PM

All replies

  • 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

    Tuesday, August 14, 2012 9:32 PM
  • 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}}

    Cheers


    Zi Feng

    TechNet Community Support

    Wednesday, August 15, 2012 9:56 AM
    Moderator
  • 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

    Wednesday, August 15, 2012 6:31 PM
  • 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

    Wednesday, August 15, 2012 6:32 PM
  • 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

    Wednesday, August 15, 2012 6:39 PM
  • 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
    Wednesday, August 15, 2012 7:42 PM
  • $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-146110729c63

    Satheshwaran Manoharan | Exchange 2003/2007/2010 | Blog:http://www.careexchange.in | Please mark it as an answer if it really helps you

    • Marked as answer by Graiggoriz Thursday, August 16, 2012 12:34 PM
    Wednesday, August 15, 2012 9:49 PM
  • 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

    Thursday, August 16, 2012 6:57 AM
  • 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!
    Thursday, August 16, 2012 12:34 PM