如何使用Regex通过PowerShell从专有名称中仅提取CN

编程入门 行业动态 更新时间:2024-10-24 08:29:20
本文介绍了如何使用Regex通过PowerShell从专有名称中仅提取CN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一堆字符串,它们是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

本文发布于:2023-10-23 01:59:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519405.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   名称   PowerShell   Regex   CN

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!