How can I use Regex to pull just the CN from a Distinguished Name with PowerShell

后端 未结 6 1831
礼貌的吻别
礼貌的吻别 2020-12-11 21:04

I have a bunch of strings that are DN\'s of groups from AD. I need to pull out the Common Name. An example string is \"CN=Group Name I Want,OU=Group Container,DC=corp,DC=tes

6条回答
  •  眼角桃花
    2020-12-11 21:46

    $s = "CN=Hall\, Jeremy,OU=Group Container,DC=corp,DC=test,DC=local"
    $s1 = ($s -split ",*..=")[1]
    $s1
    

    This works for me - however, I have a \, left in name output. (I'm pulling the manager property from the get-aduser function and it prints the distinguishedName. Hall\, Jeremy is one example of what I'm left with.

    Anyone want to take a stab?

提交回复
热议问题