我的任務是編制我們所有安全組的串列并獲取有關這些組的特定資訊,但我終其一生都無法弄清楚如何將所有資訊放到一個 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
}
我還將在另一列中添加這些組的編輯日期,這樣我們就可以看到盡管有成員但哪些組真正處于非活動狀態。
uj5u.com熱心網友回復:
為此,您需要在呼叫時使用計算的屬性運算式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,并使用成員計數填充它
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/474185.html
上一篇:合并組集合中的兩個組
