如何仅显示组用户的组名是Powershell中的成员

编程入门 行业动态 更新时间:2024-10-25 00:28:54
本文介绍了如何仅显示组用户的组名是Powershell中的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我有以下脚本,但是它列出了AD组的全名。 (例如, CN = GroupName,OU = OUName,DC = DomainName,DC = com )我如何仅指定组的名称,以便仅列出名称本身。 CN = 之后的部分。我尝试了 $ group.Name ,但没有运气。

So I have the following script but it lists the full name of the AD group. (e.g. CN=GroupName,OU=OUName,DC=DomainName,DC=com) How do I specify only the group's name, so that it lists only the name itself. The part after CN=. I tried $group.Name but no such luck.

Import-Module ActiveDirectory $userlist = Get-Content "C:\Scripts\US_User_List.txt" foreach ($username in $userlist) { $grplist = (Get-ADUser $username –Properties MemberOf | Select-Object MemberOf).MemberOf foreach ($group in $grplist) { write-host $group } }

还有第二个问题,是否有某种方法可以根据组名的开头进行过滤?

Also as a second question is there some way to filter based on what the group name starts with?

推荐答案

您可以使用 Get-ADGroup

Import-Module ActiveDirectory $userlist = Get-Content "C:\Scripts\US_User_List.txt" foreach ($username in $userlist) { $grplist = (Get-ADUser $username –Properties MemberOf).MemberOf foreach ($group in $grplist) { (Get-ADGroup $group).name } }

在第二部分中,可以使用 Where-Object / ?过滤器。

For the second part, you can use a Where-Object/? filter.

$grplist = (Get-ADUser $username –Properties MemberOf).MemberOf | ? {$_ -like "CN=StartsWithExample*"}

更多推荐

如何仅显示组用户的组名是Powershell中的成员

本文发布于:2023-11-12 12:45:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581528.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:成员   用户   组名是   Powershell

发布评论

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

>www.elefans.com

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