I need to create a powershell script that will get the members of two specific AD groups and format them in a nice to read Excel/csv file.
The output includes AD Group Name, Description, and Members. I can get the information by running these individually:
Get-ADGroupMember “domain admins” |select name |out-file d:\domain-admins.csv
Get-ADGroupMember “security_admin_group” |select name |out-file d:\security_admin_group.csv
I was looking around the Internets and this looked like it would work but I am not retrieving the AD group name or Description.
Clear-Host
$groups = Get-ADGroup “Domain Admins”
$output = ForEach ($g in $groups)
{
$results = Get-ADGroupMember -Identity $g.name -Recursive | Get-ADUser -Properties displayname, objectclass, name