すべてのPowershell
とそのsecuritygroups
をActive Directory
からエクスポートするスクリプトをmembers
で書いています。次に、.csv
の出力をフォーマットします。
コード:
$Groups = Get-ADGroup -Properties * -Filter * -SearchBase "OU=SERVICES,DC=XXXXXX,DC=XXXXX"
$Table = @()
$Record = @{
"Group Name" = ""
"Name" = ""
"Username" = ""
}
Foreach($G In $Groups)
{
$Arrayofmembers = Get-ADGroupMember -identity $G -recursive | select name,samaccountname
Foreach ($Member in $Arrayofmembers)
{
$Record."Group Name" = $G.Name
$Record."Name" = $Member.name
$Record."UserName" = $Member.samaccountname
$objRecord = New-Object PSObject -property $Record
$Table += $objrecord
}
}
$Table | export-csv "C:\temp\SecurityGroups.csv" -NoTypeInformation
結果:
"Username","Name","Group Name"
"aman","Ani Manoukian","Commercial"
"adan","Aurelia Danneels","Commercial"
"kdeb","Kathleen De Backer","Commercial"
"TVGR","Thijs Van Grimbergen","Commercial"
"SVDE","Sofie Van den Eynde","Commercial"
出力を次のようにフォーマットしたい:
"Group Name","Name","Username"
の代わりに"Username","Name","Group Name"
誰かが私を助けてくれますか?
前もって感謝します。
これはうまくいくはずです...
$Table |
Select-Object "Group Name", "Name", "Username" |
Export-Csv "C:\temp\SecurityGroups.csv" -NoTypeInformation