PoshCode Archive  Artifact [41d90e43e3]

Artifact 41d90e43e3c7c74a55c66c5d61415c20fbaf609f58ad858caa85995020065239:

  • File Convert-BounceToX500.ps1 — part of check-in [3f03b9ef8f] at 2018-06-10 13:53:45 on branch trunk — IMCEAEX-_O=CENTEGRA_OU=EXCHANGE+20ADMINISTRATIVE+20GROUP+20+28FYDIBOHF23SPDLT+29_CN=RECIPIENTS_CN=REF0428@centegra.com (user: Rohit size: 1683)

# encoding: ascii
# api: powershell
# title: Convert-BounceToX500
# description: IMCEAEX-_O=CENTEGRA_OU=EXCHANGE+20ADMINISTRATIVE+20GROUP+20+28FYDIBOHF23SPDLT+29_CN=RECIPIENTS_CN=REF0428@centegra.com
# version: 0.1
# type: script
# author: Rohit
# license: CC0
# x-poshcode-id: 5344
# x-archived: 2014-08-03T04:05:18
# x-published: 2014-07-31T14:38:00
#
#
# $Id: Convert-BounceToX500.ps1 610 2010-11-16 00:39:19Z jon $
# $Revision: 610 $

#.Synopsis
#  Convert Bounce to X500
#.Description
#  Convert URL Encoded address in a Bounce message to an X500 address
#  that can be added as an alias to the mail-enabled object
#.Parameter bounceAddress
#  URL Encoded bounce message address#
#.Example
#  Convert-BounceToX500 "IMCEAEX-_O=CENTEGRA_OU=EXCHANGE+20ADMINISTRATIVE+20GROUP+20+28FYDIBOHF23SPDLT+29_CN=RECIPIENTS_CN=REF0428@centegra.com"
#.Example
#  "IMCEAEX-_O=CENTEGRA_OU=EXCHANGE+20ADMINISTRATIVE+20GROUP+20+28FYDIBOHF23SPDLT+29_CN=RECIPIENTS_CN=REF0428@centegra.com"|Convert-BounceToX500

[CmdletBinding()]
PARAM (
	[Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$bounceAddress
)
BEGIN
{
	Add-Type -AssemblyName System.Web|Out-Null
}
PROCESS
{
	if($_) {$bounceAddress = $_}
	$bounceAddress = $bounceAddress -Replace "%2B","%" # This is a urlEncoded "+"
	$bounceAddress = $bounceAddress -Replace "%3D","="
	$bounceAddress = $bounceAddress -Replace "\+","%"
	$bounceAddress = $bounceAddress -Replace "_O=","/O="
	$bounceAddress = $bounceAddress -Replace "_OU=","/OU="
	$bounceAddress = $bounceAddress -Replace "_CN=","/CN="

	if([Web.HttpUtility]::UrlDecode($bounceAddress) -match "(/o=.*)@[\w\d.]+$"){$matches[1]}
}