• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2506
  • Last Modified:

Using powershell and get-mailbox command to display raw smtp addresses

Hi, I'm trying to pass the windowsemailaddress field from the get-mailbox command using the Exchange 2007 Powershell to another part of a script.

Unfortunately, when I use something like:

Get-Mailbox | select WindowsEmailAddress
Get-Mailbox | fl WindowsEmailAddress

it passes the column heading and some other weird characters to the variable. The actual code I'm using is included.

How can I pass raw email addresses to the next part of the script? ie. like they were from a text file and each smtp address was on a new line, no spaces or carrage returns etc.

[void][Reflection.Assembly]::LoadFile("E:\Exchange scripts\ewsutil\EWSUtil.dll")
$AllAddresses = Get-Mailbox | select WindowsEmailAddress
foreach($userEM in $AllAddresses)
$setPPTo = "0"
$casUrl = "https://fsatg10ech001/ews/exchange.asmx"
$mbMailboxEmail= $userEM
$ewc = new-object EWSUtil.EWSConnection("migrator2@# removed by modernmatt #",$true, $null, $null, $null,$casUrl)
$fldarry = new-object EWSUtil.EWS.BaseFolderIdType[] 1
$dTypeFld = new-object EWSUtil.EWS.DistinguishedFolderIdType
$dTypeFld.Id = [EWSUtil.EWS.DistinguishedFolderIdNameType]::msgfolderroot
$mbMailbox = new-object EWSUtil.EWS.EmailAddressType
$mbMailbox.EmailAddress = $mbMailboxEmail
$dTypeFld.Mailbox = $mbMailbox
$fldarry[0] = $dTypeFld
write $mbMailbox

Open in new window

1 Solution
try this:
$AllAddresses = Get-Mailbox | %{ $_.WindowsEmailAddress.ToString() }

Open in new window

Al230762Author Commented:
Dude that's awesome, thanks.

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now