我有一个PS脚本,可以查询AD的成员。工作得很好,除了输出首先是用户信息,然后是组名。我想在第一列中的组名。我试过在$Group.Name
循环中移动foreach
。没有帮助。
到目前为止,这是代码。
$groups = Get-ADGroup -Filter * -SearchBase "OU=mygroup,OU=AllGroups,DC=***,DC=local"
$Table = @()
$Record = @{
"Group Name" = ""
"Name" = ""
"Username" = ""
}
foreach ($Group in $Groups) {
$Arrayofmembers = Get-ADGroupMember -Identity $Group -Recursive # | select name,samaccountname
foreach ($Member in $Arrayofmembers) {
$Record."Name" = $Member.Name
$Record."UserName" = $Member.SamAccountName
$Record."Group Name" = $Group.Name
$objRecord = New-Object PSObject -property $Record
$Table += $objrecord
}
}
$Table | Export-Csv "D:\logs\AlfrescoUsers.csv" -NoTypeInformation
答案 0 :(得分:2)
使属性哈希表成为有序哈希表:
$Record = [ordered]@{
"Group Name" = ""
"Name" = ""
"Username" = ""
}