我有一堆字符串,它们是AD中组的DN.我需要拔出通用名称". 一个示例字符串是"CN =我想要的组名,OU =组容器,DC = corp,DC = test,DC =本地"
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=test,DC=local"
我正在寻找的是一些PowerShell代码,该代码将从该字符串中提取我想要的组名",并丢弃其余的代码.
What I am looking for is some PowerShell Code that will pull "Group Name I Want" out of that string and discard the rest.
我可以以此撕裂CN
$s = "CN=Group Name I Want,OU=Group Container,DC=corp,DC=test,DC=local" $s = $s.Remove(0,3)但是在那之后,我没有一个很好的方法来摆脱以,OU"开头的所有内容
But after that, I don't have a good way to rip off everthing starting at ",OU"
我肯定会有一些正则表达式可以做到这一点,但是我需要一些帮助来弄清楚它.
I am sure there is some regex that will do this but I need some help figuring it out.
推荐答案$s = "CN=Group Name I Want,OU=Group Container,DC=corp,DC=test,DC=local" $s -replace "(CN=)(.*?),.*",'$2'
更多推荐
如何使用Regex通过PowerShell从专有名称中仅提取CN
发布评论