PoshCode Archive  Artifact [73b49d7319]

Artifact 73b49d73192418ed316d3c9b4b938117048dd4867a9a3c2b890b415407d3e0cd:

  • File Convert-BounceToX500.ps1 — part of check-in [bd19a5618f] at 2018-06-10 14:19:40 on branch trunk — IMCEAEX-_o=Individual_ou=Exchange+20Administrative+20Group+20+28FYDIBOHF23SPDLT+29_cn=Recipients_cn=894ecd06ade243aba120f19948e5ecc8-ehd-c34e7de02@ex13.net (user: IMMTZ size: 1688)

# encoding: ascii
# api: powershell
# title: Convert-BounceToX500
# description: IMCEAEX-_o=Individual_ou=Exchange+20Administrative+20Group+20+28FYDIBOHF23SPDLT+29_cn=Recipients_cn=894ecd06ade243aba120f19948e5ecc8-ehd-c34e7de02@ex13.net
# version: 0.1
# type: script
# author: IMMTZ
# license: CC0
# x-poshcode-id: 6707
# x-archived: 2017-01-24T08:06:03
# x-published: 2017-01-20T14:44: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]}
}