如何拆分DistinguishedName? [英] How to Split DistinguishedName?

查看:234
本文介绍了如何拆分DistinguishedName?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个来自AD的人员及其DN的列表(我无法直接访问该AD).它们的DN格式为:

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=Agency,OU=NorthState,DC=myworld,DC=com',
          'CN=Ray Charles,OU=Contractors,OU=Dept,OU=Agency,OU=NorthState,DC=myworld,DC=com',
          'CN=Martin Sheen,OU=Users,OU=Dept,OU=Agency,OU=WaySouth,DC=myworld,DC=com'

我想让$DNList返回以下内容:

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

推荐答案

我决定将我的评论变成答案:

I decided to turn my comment into an answer:

$DNList | ForEach-Object {
    $_ -replace '^.+?(?<!\\),',''
}

Debuggex演示

这将正确处理作为第一个组件一部分的转义逗号.

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).

这篇关于如何拆分DistinguishedName?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆