Skip to content

Instantly share code, notes, and snippets.

@IISResetMe
Created December 22, 2014 17:08
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 IISResetMe/69453fcef29419a79e8a to your computer and use it in GitHub Desktop.
Save IISResetMe/69453fcef29419a79e8a to your computer and use it in GitHub Desktop.
Leverage the power of RegEx!
# Negative lookbehind
function Split-DN{
param([String]$DN)
return $DN-split"(?<!\\),"
}
# Positive lookbehind with negative expression
function Split-DN{
param([String]$DN)
return $DN-split"(?<=[^\\]),"
}
# Usage:
Split-DN -DN "CN=User\, A Friendly,OU=Idiotas,DC=domain,DC=tld"
# Returns an ordered array containing each component in the DN: @("CN=User\, A Friendly","OU=Idiotas","DC=domain","DC=tld")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment