Hi Team,
I am working on file server migration project. I am trying to export data in csv file for AD groups and their members. I want to export data in csv below format:
ADGroup1 ADGroup2
Jason Ross Joe Butler
Anthony Davis Jerry Anderson
I am using below script. It is working for one AD group if I have in txt file. If I add multiple groups in my text file, it overrides to the previous one. I need guidance to export the data for multiple AD groups.
$groups = Get-Content C:\temp\ADGroups.txt
$groupname = @()
$groupmember = @()
foreach ($g in $groups){
$groupname += Get-ADGroup -Identity $g | Select-Object -ExpandProperty Name
$groupmember += Get-ADGroupMember -Identity $g |
Select-Object -ExpandProperty SamAccountName
for ($i = 0; $i -le $groupmember.Count; $i++) {
[PSCustomObject]@{
$g = $groupmember[$i]
} | Export-Csv -Path C:\temp\result.csv -Append -NoTypeInformation
}
}
Any help would be appreciated.
Thanks
Jatinder