Script to show Email Forwarding for Exchange 2007. (Help with Formatting)
I'm trying to write a script that will allow me to see which users emails are being forwarded to whom. Using a script I have created in the past and using some information from the web I've managed to create a script that will get me the information but I'm having trouble formatting it. Could someone take a look a point me in the right direction? Using this script the Forwarding Address is coming up as DOMAIN\OU\User and is to long, I really only need the user. Thanks in advance. The script is as follows; $FromAddress = "SENDING EMAIL ADDRESS" $ToAddress = "MY EMAIL ADDRESS" $MessageSubject = "Mailbox Divert Report" $MessageBody = "Attached is the current list email diverts." $SendingServer = "MY MAIL SERVER" Get-Mailbox | Where {$_.ForwardingAddress -ne $null} | Select Name, ForwardingAddress, DeliverToMailboxAndForward| Sort-Object Name | ft Name,ForwardingAddress,DeliverToMailboxAndForward -auto > diverts.txt $SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody $Attachment = New-Object Net.Mail.Attachment("C:\USER PATH ETC\diverts.txt") $SMTPMessage.Attachments.Add($Attachment) $SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer $SMTPClient.Send($SMTPMessage)
December 28th, 2011 3:12pm

Thanks for the reply. This does work in removing the Domain\OU references, but I also need to see if the original mailbox/user is still be copied in on their mail. AStaley
Free Windows Admin Tool Kit Click here and download it now
December 30th, 2011 7:58am

Hi Sorry, I miss a parameterjust add the DeliverToMailboxAndForward in to the script So it will be Get-Mailbox | Where {$_.ForwardingAddress -ne $null} | Select-Object Name,@{Name='Forwarding'; Expression={[String]::join(";",((Get-Mailbox -identity$_.identity).ForwardingAddress.Name))}},DeliverToMailboxAndForward | Sort-Object Name > diverts.txt Cheers Zi Feng
December 30th, 2011 9:05pm

Hi Change the following Command Get-Mailbox | Where {$_.ForwardingAddress -ne $null} | Select Name, ForwardingAddress, DeliverToMailboxAndForward| Sort-Object Name | ft Name,ForwardingAddress,DeliverToMailboxAndForward -auto > diverts.txt to Get-Mailbox | Where {$_.ForwardingAddress -ne $null} | Select-Object Name,@{Name='Forwarding'; Expression={[String]::join(";",((Get-Mailbox -identity $_.identity).ForwardingAddress.Name))}} | Sort-Object Name > diverts.txt It will just display the User Cheers Zi Feng
Free Windows Admin Tool Kit Click here and download it now
December 31st, 2011 3:27am

Strange, if I copy and paste your code as is then I get; [PS] C:\users\Administrator.XXXX.XXXX\Documents>Get-Mailbox | Where {$_.For wardingAddress -ne $null} | Select-Object Name,@{Name='Forwarding'; Expression={ [String]::join(";",((Get-Mailbox -identity$_.identity).ForwardingAddress.Name))} },DeliverToMailboxAndForward | Sort-Object Name Name Forwarding DeliverToMailboxAndForwar d ---- ---------- ------------------------- Alan Exxx True Alan Oxxx True Alison Wxxx True But if I take your code from the previous post and add the entry at the end as you suggested it works as expected. [PS] C:\users\Administrator.XXXX.XXXX\Documents>Get-Mailbox | Where {$_.For wardingAddress -ne $null} | Select-Object Name,@{Name='Forwarding'; Expression={ [String]::join(";",((Get-Mailbox -identity $_.identity).ForwardingAddress.Name)) }},DeliverToMailboxAndForward | Sort-Object Name Name Forwarding DeliverToMailboxAndForwar d ---- ---------- ------------------------- Alan Exxx Jenny Lxxx True Alan Oxxx Hayley Txxx True Alison Wxxx Claire Bxxx True I've looked at the two codes and can't see where the difference is, perhaps something to do with copy/paste adding a space in I've missed maybe. Either way I appreciate your help in giving me the answer to my problem. AStaley.
December 31st, 2011 4:57am

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

Other recent topics Other recent topics