PoshCode Logo PowerShell Code Repository

Convert-BounceToX500 by Rafael 8 days ago (modification of post by Test1 view diff)
View followups from rafael | diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/6800"></script>download | new post

IMCEAEX-_O%3DEXG_OU%3DEXCHANGE%2B20ADMINISTRATIVE%2B20GROUP%2B20%2B28FYDIBOHF23SPDLT%2B29_CN%3DRECIPIENTS_CN%3DBiasutto%2B2C%2B20Delfina336@OFC.LOC

  1. # $Id: Convert-BounceToX500.ps1 610 2010-11-16 00:39:19Z jon $
  2. # $Revision: 610 $
  3.  
  4. #.Synopsis
  5. #  Convert Bounce to X500
  6. #.Description
  7. #  Convert URL Encoded address in a Bounce message to an X500 address
  8. #  that can be added as an alias to the mail-enabled object
  9. #.Parameter bounceAddress
  10. #  URL Encoded bounce message address#
  11. #.Example
  12. #  Convert-BounceToX500 "IMCEAEX-_O=CONTOSO_OU=First+20Administrative+20Group_cn=Recipients_cn=john+5Fjacob+2Esmith@contoso.com"
  13. #.Example
  14. #  "IMCEAEX-_O=CONTOSO_OU=First+20Administrative+20Group_cn=Recipients_cn=john+5Fjacob+2Esmith@contoso.com"|Convert-BounceToX500
  15.  
  16. [CmdletBinding()]
  17. PARAM (
  18.         [Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$bounceAddress
  19. )
  20. BEGIN
  21. {
  22.         Add-Type -AssemblyName System.Web|Out-Null
  23. }
  24. PROCESS
  25. {
  26.         if($_) {$bounceAddress = $_}
  27.         $bounceAddress = $bounceAddress -Replace "%2B","%" # This is a urlEncoded "+"
  28.         $bounceAddress = $bounceAddress -Replace "%3D","="
  29.         $bounceAddress = $bounceAddress -Replace "\+","%"
  30.         $bounceAddress = $bounceAddress -Replace "_O=","/O="
  31.         $bounceAddress = $bounceAddress -Replace "_OU=","/OU="
  32.         $bounceAddress = $bounceAddress -Replace "_CN=","/CN="
  33.  
  34.         if([Web.HttpUtility]::UrlDecode($bounceAddress) -match "(/o=.*)@[\w\d.]+$"){$matches[1]}
  35. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me