PowerShell脚本返回多个安全组的成员 [英] PowerShell script to return members of multiple security groups

查看:119
本文介绍了PowerShell脚本返回多个安全组的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用PowerShell返回多个安全组的所有成员。方便地,所有组都以相同的字母开头。

I need to return all members of multiple security groups using PowerShell. Handily, all of the groups start with the same letters.

我可以使用以下代码返回所有相关安全组的列表:

I can return a list of all the relevant security groups using the following code:

Get-ADGroup -filter 'Name -like"ABC*"' | Select-Object Name

我知道我可以使用以下命令返回特定安全组的成员身份列表代码:

And I know I can return the membership list of a specific security group using the following code:

Get-ADGroupMember "Security Group Name" -recursive | Select-Object Name

但是,尽管我认为我想'之后应该看起来像这样(请随时纠正我,这就是为什么我在这里!):

However, I can't seem to put them together, although I think what I'm after should look something like this (please feel free to correct me, that's why I'm here!):

$Groups = Get-ADGroup -filter 'Name -like"ABC*"' | Select-Object Name
ForEach ($Group in $Groups) {Get-ADGroupMember -$Group -recursive | Select-Object Name

关于如何正确构造任何想法的任何想法!

Any ideas on how to properly structure that would be appreciated!

谢谢

Chris

推荐答案

如果您不关心用户所在的组,而只希望列出大量用户,则可以完成此工作:

If you don't care what groups the users were in, and just want a big ol' list of users - this does the job:

$Groups = Get-ADGroup -Filter {Name -like "AB*"}

$rtn = @(); ForEach ($Group in $Groups) {
    $rtn += (Get-ADGroupMember -Identity "$($Group.Name)" -Recursive)
}

然后结果:

$rtn | ft -autosize

这篇关于PowerShell脚本返回多个安全组的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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