导出不是某些组成员的组的 csv
Export csv of groups that are not members of some groups
我正在导出一些 "are not member of" 的用户和组。但是我在使用组时遇到了麻烦,我对用户进行了操作,但我不知道如何对组进行同样的操作。
在此示例中,我导出了不属于该组的用户。
$groups = 'GG_LCS_UsersType4', 'GG_LCS_UsersType3', 'GG_LCS_UsersType2', 'GG_LCS_SpecialUsers'
$whereFilter = $groups | Foreach-Object {
$g = (Get-ADGroup -server $domain $_).DistinguishedName
"{0} '{1}'" -f '$_.memberOf -notcontains',$g
}
$whereFilter = [scriptblock]::Create($whereFilter -join " -and ")
$users = (Get-ADUser -server $Domain -filter {objectclass -eq "user"} -properties memberof).where($whereFilter)
$users | Select-Object SamAccountName,Enabled |
Export-Csv "${Domain}_Users_withoutGG.csv" -NoTypeInformation -Encoding UTF8 -Append
所以我也想要群组。你能帮帮我吗?
谢谢!
从技术上讲,您应该能够在发布的代码末尾添加一个 Get-ADGroup
命令,然后导出所需的数据。
$FilteredGroups = (Get-ADGroup -Server $Domain -Filter * -Properties MemberOf).where($whereFilter)
$FilteredGroups | Select-Object SamAccountName |
Export-Csv "groups.csv" -NoTypeInformation -Encoding UTF8 -Append
我正在导出一些 "are not member of" 的用户和组。但是我在使用组时遇到了麻烦,我对用户进行了操作,但我不知道如何对组进行同样的操作。
在此示例中,我导出了不属于该组的用户。
$groups = 'GG_LCS_UsersType4', 'GG_LCS_UsersType3', 'GG_LCS_UsersType2', 'GG_LCS_SpecialUsers'
$whereFilter = $groups | Foreach-Object {
$g = (Get-ADGroup -server $domain $_).DistinguishedName
"{0} '{1}'" -f '$_.memberOf -notcontains',$g
}
$whereFilter = [scriptblock]::Create($whereFilter -join " -and ")
$users = (Get-ADUser -server $Domain -filter {objectclass -eq "user"} -properties memberof).where($whereFilter)
$users | Select-Object SamAccountName,Enabled |
Export-Csv "${Domain}_Users_withoutGG.csv" -NoTypeInformation -Encoding UTF8 -Append
所以我也想要群组。你能帮帮我吗?
谢谢!
从技术上讲,您应该能够在发布的代码末尾添加一个 Get-ADGroup
命令,然后导出所需的数据。
$FilteredGroups = (Get-ADGroup -Server $Domain -Filter * -Properties MemberOf).where($whereFilter)
$FilteredGroups | Select-Object SamAccountName |
Export-Csv "groups.csv" -NoTypeInformation -Encoding UTF8 -Append