本文介绍了如何仅显示组用户的组名是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中的成员
发布评论