How to Split DistinguishedName?

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

    You have 7 items per user, comma separated and you want rid of the first one.

    So, split each item in the array using commas as the delimiter, return matches 1-6 (0 being the first item that you want to skip), then join with commas again e.g.

    $DNList = $DNList|foreach{($_ -split ',')[1..6] -join ','}
    

    If you then enter $DNList it returns

    OU=Users,OU=Dept,OU=Agency,OU=NorthState,DC=myworld,DC=com
    OU=Contractors,OU=Dept,OU=Agency,OU=NorthState,DC=myworld,DC=com
    OU=Users,OU=Dept,OU=Agency,OU=WaySouth,DC=myworld,DC=com
    

提交回复
热议问题