Ever needed to export the list of mailbox of your Microsoft Exchange 2007 with all alias and all the smtp addresses? Try this with this command:
Get-Mailbox | select name , alias ,EmailAddresses | foreach { "Name: "+$_.name "Alias: "+$_.alias $_.EmailAddresses | foreach { if($_.SmtpAddress){ if($_.IsPrimaryAddress){ "Primary SmtpAddress: $($_.SmtpAddress)" } else { "SmtpAddress: $($_.SmtpAddress)" } } } write-output "" } > c:\smtp.txt
or use the out-file cmdlet..
######### Using Out-File Cmdlet ############ Get-Mailbox | select name , alias ,EmailAddresses | foreach { "Name: "+$_.name "Alias: "+$_.alias $_.EmailAddresses | foreach { if($_.SmtpAddress){ if($_.IsPrimaryAddress){ "Primary SmtpAddress: $($_.SmtpAddress)" } else { "SmtpAddress: $($_.SmtpAddress)" } } } write-output "" } | out-file -filepath c:\smtp.txt -encoding ASCII