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:17am

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
Free Windows Admin Tool Kit Click here and download it now
August 15th, 2012 5:56am

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
August 15th, 2012 2:31pm

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
Free Windows Admin Tool Kit Click here and download it now
August 15th, 2012 2:32pm

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
August 15th, 2012 2:39pm

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
Free Windows Admin Tool Kit Click here and download it now
August 15th, 2012 3:42pm

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
August 16th, 2012 2:57am

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!
Free Windows Admin Tool Kit Click here and download it now
August 16th, 2012 8:34am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics