Solved

Powershell Exchange Script - Export Forwarded Email

Posted on 2014-12-12
3
273 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 68

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

We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
A brief introduction to what I consider to be the best editor for PowerShell.
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

914 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now