Solved

Powershell Exchange Script - Export Forwarded Email

Posted on 2014-12-12
3
291 Views
Last Modified: 2014-12-15
Hi Experts,

I have the following script:

Get-Mailbox -Filter {ForwardingAddress -ne
$null} | foreach {$recipient = $_; $forwardingsmtp = (Get-Recipient $_.ForwardingAddress).PrimarySmtpAddress; 
Write-Host $recipient.Name, $forwardingsmtp, $recipient.DeliverToMailboxAndForward } 

Open in new window


I need the output to outputted to a CSV showing the following:

User, User Primary SMTP and Forwarding SMTP address.

I am only able to view this on the command view and cannot seem to output this to a CSV.

Any help will be appreciated.

Regards,

introlux

Using: Exchange 2007 Standard
0
Comment
Question by:introlux
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Expert Comment

by:tshearon
ID: 40495942
Have you tried just adding another pipe at the end and using the export-csv function?

| export-csv c:\report.csv
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40495954
That won't work, because the Write-Host generates a single string without properties and delimiters.
Trivial, self-formatting way:
Get-Mailbox -Filter {ForwardingAddress -ne $null} |
  % {
    $recipient = $_
    $forwardingsmtp = (Get-Recipient $_.ForwardingAddress).PrimarySmtpAddress
    Write-Host "$($recipient.Name),$forwardingsmtp,$($recipient.DeliverToMailboxAndForward)"
  } | out-file 'text.csv'

Open in new window

Better:
Get-Mailbox -Filter {ForwardingAddress -ne $null} |
  % {
    New-Object PsObject -Property @{
      recipient = $_.Name
      forwardingsmtp = (Get-Recipient $_.ForwardingAddress).PrimarySmtpAddress
      DeliverToMailboxAndForward = $_.DeliverToMailboxAndForward
    }
  } | export-csv -notype 'text.csv'

Open in new window

0
 

Author Closing Comment

by:introlux
ID: 40500158
Spot on!!

Thanks,

introlux
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
how to add IIS SMTP to handle application/Scanner relays into office 365.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question