合并2个脚本
我的任务是编译我们所有安全组的列表并获取有关这些组的特定信息,但我无法确定如何将所有信息获取到一个CSV上。
这在从这些组中获取我需要的所有批量项目方面做得很好。
Get-ADGroup -Filter * |
where {$_.GroupCategory -eq "security"} |
Where {$_.DistinguishedName -notlike "*OU=Builtin*"} |
Where {$_.DistinguishedName -notlike "*CN=Builtin*"} |
Where {$_.DistinguishedName -notlike "*OU=Microsoft Exchange Security Groups*"} |
Select DistinguishedName, GroupScope, Name, SamAccountName |
Export-csv -LiteralPath C:\Results\ListSecGroups.csv -NoTypeInformation
而且该脚本是我尝试将所有信息与小组成员计数的计数一起进行编译。
$Groups = Get-ADGroup -Filter * |
where {$_.GroupCategory -eq "security"} |
Where {$_.DistinguishedName -notlike "*OU=Builtin*"} |
Where {$_.DistinguishedName -notlike "*CN=Builtin*"} |
Where {$_.DistinguishedName -notlike "*OU=Microsoft Exchange Security Groups*"}
ForEach ($Group in $Groups){
(Get-ADGroup $Group.DistinguishedName -Properties *).member.count
Select DistinguishedName, GroupScope, Name, SamAccountName |
Export-csv -LiteralPath C:\Results\ListSecGroups.csv -NoTypeInformation -Append
}
我还将在编辑这些组的日期中添加另一列列,这样我们就可以看到哪些组确实没有成员。
I've been tasked with compiling a list of all our security groups and grabbing specific information about these groups but I cannot for the life of me figure out how to get all the information onto one Csv.
This does a great job at getting all the bulk items I need from these groups.
Get-ADGroup -Filter * |
where {$_.GroupCategory -eq "security"} |
Where {$_.DistinguishedName -notlike "*OU=Builtin*"} |
Where {$_.DistinguishedName -notlike "*CN=Builtin*"} |
Where {$_.DistinguishedName -notlike "*OU=Microsoft Exchange Security Groups*"} |
Select DistinguishedName, GroupScope, Name, SamAccountName |
Export-csv -LiteralPath C:\Results\ListSecGroups.csv -NoTypeInformation
And this script is my attempt at getting all the information to compile together with a count of the group memberships.
$Groups = Get-ADGroup -Filter * |
where {$_.GroupCategory -eq "security"} |
Where {$_.DistinguishedName -notlike "*OU=Builtin*"} |
Where {$_.DistinguishedName -notlike "*CN=Builtin*"} |
Where {$_.DistinguishedName -notlike "*OU=Microsoft Exchange Security Groups*"}
ForEach ($Group in $Groups){
(Get-ADGroup $Group.DistinguishedName -Properties *).member.count
Select DistinguishedName, GroupScope, Name, SamAccountName |
Export-csv -LiteralPath C:\Results\ListSecGroups.csv -NoTypeInformation -Append
}
I will also be adding in another column for the date these groups have been edited, that way we can see what groups are truly inactive despite having members.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,您需要使用计算的属性表达式
select-object
:这将为每个输入对象创建一个名为
MemberCount
的新属性,并用它填充它成员计数For this you'll want to use a calculated property expression when calling
Select-Object
:This will create a new property named
MemberCount
for each input object, and populate it with the member count