Solved

Powershell Exchange Script - Export Forwarded Email

Posted on 2014-12-12
3
280 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
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 69

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
In this video we show how to create an email address policy in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Mail Flow…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

803 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