Solved

Powershell Exchange Script - Export Forwarded Email

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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

A list of top three free exchange EDB viewers that helps the user to extract a mailbox from an unmounted .edb file and get a clear preview of all emails & other items with just a single click on mailboxes.
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…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

707 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