How to Split DistinguishedName?

后端 未结 4 768
孤独总比滥情好
孤独总比滥情好 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:19

    You can remove the first element with a replacement like this:

    $DNList -replace '^.*?,(..=.*)$', '$1'
    

    ^.*?, is the shortest match from the beginning of the string to a comma.
    (..=.*)$ matches the rest of the string (starting with two characters after the comma followed by a = character) and groups them, so that the match can be referenced in the replacement as $1.

提交回复
热议问题