My script looks great on console, but I would like to write/export the results to a .csv
file. I tried creating a variable, and then pipe the result to another cmdlet
, but that doesn't seem to work because of the additional pipe before my loop starts.
Get-ADGroup -Server "company.com" -Properties * -Filter * -SearchBase "OU=Groups,OU=Users,OU=Corporate,..."
| Sort-Object Name
| ForEach-Object{
$_ | Select-Object Name,@{
Name = 'User'
Expression = {Get-ADGroupMember -Identity $_
| Select-Object -ExpandProperty name}
}
}
| Where-Object {$_.Name}
Thanks for your help.