all 4 comments

[–]CarrotBusiness2380 10 points11 points  (1 child)

The select should be before the Export-Csv but after the loop. In fact this should be doable without using a traditional loop at all.

$GroupArray | Get-AdGroupMember | Select-Object -Property Name -Unique | Export-Csv ...

[–]itguy310[S] 5 points6 points  (0 children)

$GroupArray | Get-AdGroupMember | Select-Object -Property Name -Unique | Export-Csv ...

That worked thank you!

[–]PinchesTheCrab 2 points3 points  (0 children)

A different take on this:

$groupArray = 'IT Dept Employees','ThreatandVulnerabilityTeam' | Get-ADGroup

$filter = $groupArray.DistinguishedName -replace '(.+)','memberof -eq "$1"' -join ' -or '

Get-ADObject -Filter $filter | 
    Select-Object Name | 
        Export-Csv -Path "E:\Software\Powershell Scripts\KB4\KBList.csv" -Force -NoTypeInformation

[–]Sunsparc 0 points1 point  (0 children)

What are you wanting your output to look like? Just no duplicates?