Hi, my name is Sasi,
I am need to create an script which can give me a report that goes through certain AD groups and reports out only unique Titles and Departments on those groups.
Experimenting with pscustomobject but whenever I output it just shows the columns with an array of information under neath.
$report = @()
$Distros = Get-ADGroup | ? {$_.Name - like “Critical - *”
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
$uTitles = $DistroMembers | select Title -unique
$uDepartments = $DistroMembers | select Department -unique
$UniqueTitle = $uTitles.Title
$UniqueDepartments = $uDepartments.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 $UniqueTitle
$obj | Add-Member -MemberType NoteProperty -Name Department -Value $UniqueDepartments
$report += $obj
}