Skip to content

Instantly share code, notes, and snippets.

@JeremyTBradshaw
Created August 5, 2022 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeremyTBradshaw/5ddd4743cbac555710bfdb3a00bfba6a to your computer and use it in GitHub Desktop.
Save JeremyTBradshaw/5ddd4743cbac555710bfdb3a00bfba6a to your computer and use it in GitHub Desktop.
Convert DistinguishedName's to CanonicalName's
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