Powershell Active Directory - array output formatting help
I am working on a Powershell script that will go through the memberships of AD groups that begin with a certain name and then output the group name along with only unique Titles and Departments of members.
So for example if there are two people in a group with the same title and department, I'm aiming to get it to output like this, where it has group name, and then the Title column and Department column with unique ones.
Now I could do this to Excel if that works and just remove duplicates to make it easier.
But the issue I'm having is that the Title and Department values always output as an array.
Results style I'd like to yield:
Group name: "Emergency - All"
Title | Department
IT Admin | IT
Technician | Facilities
Group name: "Emergency - Facilities"
Title | Department
Technician | Facilities
And so on and so forth for each group....
How results are currently yielding:
Title Department
----- ----------
{IT Admin , Technician...} {Facilities...
Obviously that creates a problem for both readability and exporting.
It's an array with commas and I don't know how to overcome it.
The script I currently have is:
$report = @()$Distros = Get-ADGroup -filter * | ? {$_.Name -like "Emergency - *"} foreach ($Distro in $Distros){ $DistroMembers = Get-ADGroupMember -Identity $Distro.SID -Recursive | Where objectclass -eq 'user' | Get-ADUser -Properties Displayname,Title,Department | Select DistinguishedName,samAccountName,Name,Displayname,Title,Department #add line to object $obj = New-Object -TypeName PSObject $obj | Add-Member -MemberType NoteProperty -Name Group -Value $Distro.Name $obj | Add-Member -MemberType NoteProperty -Name Title -Value ($DistroMembers | select Title -unique).title $obj | Add-Member -MemberType NoteProperty -Name Department -Value ($DistroMembers | select Department -unique).department $report += $obj }