PoshCode Logo PowerShell Code Repository

Difference between
modified post 6776 by Sabrina Olsen on Wed 8th Mar 12:34 and
original post 6721 by breto on Mon 6th Feb 11:43
Showold version | new version | both versions

    
11
# $Id: Convert-BounceToX500.ps1 610 2010-11-16 00:39:19Z jon $
22
# $Revision: 610 $
44
#.Synopsis
55
#  Convert Bounce to X500
66
#.Description
77
#  Convert URL Encoded address in a Bounce message to an X500 address
88
#  that can be added as an alias to the mail-enabled object
99
#.Parameter bounceAddress
1010
#  URL Encoded bounce message address#
1111
#.Example
1212
#  Convert-BounceToX500 "IMCEAEX-_O=CONTOSO_OU=First+20Administrative+20Group_cn=Recipients_cn=john+5Fjacob+2Esmith@contoso.com"
1313
#.Example
1414
#  "IMCEAEX-_O=CONTOSO_OU=First+20Administrative+20Group_cn=Recipients_cn=john+5Fjacob+2Esmith@contoso.com"|Convert-BounceToX500
1616
[CmdletBinding()]
1717
PARAM (
1818
	[Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$bounceAddress
1919
)
2020
BEGIN
2121
{
2222
	Add-Type -AssemblyName System.Web|Out-Null
2323
}
2424
PROCESS
2525
{
2626
	if($_) {$bounceAddress = $_}
2727
	$bounceAddress = $bounceAddress -Replace "%2B","%" # This is a urlEncoded "+"
2828
	$bounceAddress = $bounceAddress -Replace "%3D","="
2929
	$bounceAddress = $bounceAddress -Replace "\+","%"
3030
	$bounceAddress = $bounceAddress -Replace "_O=","/O="
3131
	$bounceAddress = $bounceAddress -Replace "_OU=","/OU="
3232
	$bounceAddress = $bounceAddress -Replace "_CN=","/CN="
3434
	if([Web.HttpUtility]::UrlDecode($bounceAddress) -match "(/o=.*)@[\w\d.]+$"){$matches[1]}
3535
}

ContributeMost Recent Contributions (feed)

Contribute ... Next Page