How to Split DistinguishedName?

后端 未结 4 767
孤独总比滥情好
孤独总比滥情好 2020-12-21 11:14

I have a list of folks and their DN from AD (I do not have direct access to that AD). Their DNs are in format:

$DNList = \'CN=Bob Dylan,OU=Users,OU=Dept,OU=         


        
4条回答
  •  佛祖请我去吃肉
    2020-12-21 11:24

    I decided to turn my comment into an answer:

    $DNList | ForEach-Object {
        $_ -replace '^.+?(?

    Regular expression visualization

    Debuggex Demo

    This will correctly handle escaped commas that are part of the first component.

    We do a non-greedy match for one or more characters at the beginning of the string, then look for a comma that is not preceded by a backslash (so that the dot will match the backslash and comma combination and keep going).

提交回复
热议问题