PoshCode Archive  Artifact [7f8432687d]

Artifact 7f8432687da906123f9933b7c080acabaec826ab05cc1b07fc770f416bee7b10:

  • File Convert-BounceToX500.ps1 — part of check-in [38c9b82bbf] at 2018-06-10 14:06:51 on branch trunk — IMCEAEX-_O=EXCHANGELABS_OU=EXCHANGE+20ADMINISTRATIVE+20GROUP+20+28FYDIBOHF23SPDLT+29_CN=RECIPIENTS_CN=5db7eb6d37784f2eaccf09b2f90b75e8-katstewart+40coca-cola+2Ecom@namprd07.prod.outlook.com (user: Allison size: 1724)

# encoding: ascii
# api: powershell
# title: Convert-BounceToX500
# description: IMCEAEX-_O=EXCHANGELABS_OU=EXCHANGE+20ADMINISTRATIVE+20GROUP+20+28FYDIBOHF23SPDLT+29_CN=RECIPIENTS_CN=5db7eb6d37784f2eaccf09b2f90b75e8-katstewart+40coca-cola+2Ecom@namprd07.prod.outlook.com
# version: 0.1
# type: script
# author: Allison
# license: CC0
# x-poshcode-id: 6044
# x-archived: 2016-05-17T08:26:19
# x-published: 2016-10-13T05:59: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=CONTOSO_OU=First+20Administrative+20Group_cn=Recipients_cn=john+5Fjacob+2Esmith@contoso.com"
#.Example
#  "IMCEAEX-_O=CONTOSO_OU=First+20Administrative+20Group_cn=Recipients_cn=john+5Fjacob+2Esmith@contoso.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]}
}