合并2个脚本

发布于 2025-01-28 03:16:37 字数 1151 浏览 1 评论 0原文

我的任务是编译我们所有安全组的列表并获取有关这些组的特定信息,但我无法确定如何将所有信息获取到一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你又不是我 2025-02-04 03:16:37

为此,您需要使用计算的属性表达式select-object

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, @{Name='MemberCount';Expression={(Get-ADGroup $_.DistinguishedName -Properties member).member.Count}} |
  Export-csv -LiteralPath C:\Results\ListSecGroups.csv -NoTypeInformation

这将为每个输入对象创建一个名为MemberCount的新属性,并用它填充它成员计数

For this you'll want to use a calculated property expression when calling Select-Object:

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, @{Name='MemberCount';Expression={(Get-ADGroup $_.DistinguishedName -Properties member).member.Count}} |
  Export-csv -LiteralPath C:\Results\ListSecGroups.csv -NoTypeInformation

This will create a new property named MemberCount for each input object, and populate it with the member count

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文