I have a need to get all of the AD groups and their respective memberships out of a specific AD OU. The code I have does that when writing to the host screen but I am not able to output it cleanly to .xml, which was the requested format, but at this point I will take it in any format. Management would like output file similar to :
Group1 User1
Group1 User2
Group1 User3
Group2 User1
Group2 User2
Group2 User3
etc...
Anyone have any ideas?
$groupName = Get-ADGroup -SearchBase "OU=Groups,DC=domain,DC=com" -Filter * | Select-Object sAMAccountName
foreach ( $groupMember in $groupName )
{
# $groupMember
Get-ADGroupMember -Identity $groupMember.sAMAccountName | Export-Clixml -Path C:\temp.xml -Force