Advertisement
anonit

Get the smtp alias of a mailbox on a remote Exchange server

Jun 19th, 2018
1,028
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. .SYNOPSIS
  3. Get the smtp alias of a mailbox on a remote Exchange server
  4.  
  5. .DESCRIPTION
  6. Get the smtp alias of a mailbox on a remote Exchange server
  7.  
  8. .EXAMPLE
  9. ./ListSMTPAlias.ps1 -ExchUri http://anonit.net/powershell -mailbox anonit
  10.  
  11. .NOTES
  12.  
  13.  
  14. .LINK
  15. http://anonit.net
  16.  
  17. #>
  18.  
  19.  
  20. param(
  21.         [uri]$ExchUri="http://anonit.net/powershell",
  22.         [Parameter(Mandatory=$true)][string]$Mailbox
  23. )
  24.  
  25.  
  26.  
  27. $exchSession=New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $exchUri -Authentication Kerberos
  28.  
  29. # Import the session, redirect the import-session command output to null to remove the output from the import (exported commands, etc)
  30. Import-PSSession $exchSession | out-null
  31. $SMTPAddresses=get-recipient -identity $Mailbox| select emailaddresses -ExpandProperty emailaddresses
  32. # The output of this command places smtp: and SMTP: infront of the email addresses, use a double replace to remove smtp: and SMTP:
  33. $SMTPAddresses.replace("smtp:","").replace("SMTP:","")
  34. # close the session
  35. Remove-PSSession $exchSession
  36.  
  37. # References https://community.spiceworks.com/scripts/show/3956-connect-to-exchange-powershell-remotely
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement