I have created the script below to get all groups and member in each group. The script can write out put to the console. But I need help to write output to a text file or csv file. Understood that foreach will have nothing for the pipeline but I couldn’t find out the solution. Here is my simple script. Thanks for your help.
$ADgroupList = Get-ADGroup -server busybox.local -Filter * -SearchBase “OU=Sales,DC=busybox,DC=local”
ForEach($Group in $ADGroupList)
$members=Get-ADGroupMember -Identity $Group | Select Name, SAMAccountName | Sort
ForEach($member in $members)
Write-Host ($member.Name + “,” + $member.SAMAccountName + “,” + $Group.name)