我有一个脚本来收集每组中的AD组和成员数。 任何人都可以帮我导出csv中的输出
$GroupArray = Get-ADGroup -Properties Modified, Members -Filter * -SearchBase "DC=oimstage,DC=corp,DC=com"
Foreach($Group In $GroupArray)
{
Write-Host
Write-Host "Group Name:"$Group.Name
Write-Host "Total members:"($Group.Members).count
Write-Host "Modified date:"$Group.modified
Write-Host
}
答案 0 :(得分:0)
您希望使用custom PowerShell object
导出选择性属性。试试这个 -
$GroupArray = @()
Get-ADGroup -Properties Modified, Members -Filter * -SearchBase "DC=oimstage,DC=corp,DC=com" |
ForEach-Object {
$obj = New-Object PSObject
$obj | Add-Member -MemberType NoteProperty -Name "Group Name" $_.Name
$obj | Add-Member -MemberType NoteProperty -Name "Total members" $_.Members.Count
$obj | Add-Member -MemberType NoteProperty -Name "Modified date" $_.modified
$GroupArray += $obj
}
您可以向自定义对象添加任意数量的属性并将其存储在数组中。然后,您可以通过csv
cmdlet将数组导出到Export-Csv
。您可以根据自己的要求修改$obj
。