Created
August 5, 2022 12:01
-
-
Save JeremyTBradshaw/5ddd4743cbac555710bfdb3a00bfba6a to your computer and use it in GitHub Desktop.
Convert DistinguishedName's to CanonicalName's
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ConvertFrom-DistinguishedName ($DistinguishedName) { | |
$Domain = ($DistinguishedName -split ',DC=' | Where-Object { $_ -notmatch '^CN=' }) -join '.' | |
$CNPath = ($DistinguishedName -split ',DC=' | Where-Object { $_ -match '^CN=' }) -split ',\w\w=' | |
[array]::Reverse($CNPath) | |
($Domain + '/' + ($CNPath -join '/')) -replace 'CN=' -replace '\\' | |
} | |
ConvertFrom-DistinguishedName "CN=Bradshaw\, Jeremy,OU=PowerShell,DC=Sample,DC=code" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment