I am looking at a way to list how many times an AD property matching a certain value appears against each user.
Specifically - Users in our AD have a Custom Attribute distinguishing their company. I need to run monthly reports that will display a list of all companies and how many users are listed.
This is as close as I have it - but it is not user friendly for our Accounts team.
import-csv c:\HostedCompanyList.csv -header ID |
$total = (get-aduser -filter "(extensionattribute1 -eq '$($_.ID)') -and (extensionattribute2 -eq 'billed')" -properties *).count
write-host $total $_.ID
Untested, since I don't have the same extension attributes, but this shape:
should work with one query, no text file to read from, and csv export.
$filter = "extensionattribute2 -eq 'billed'" $users = Get-ADUser -filter $filter -Property extensionattribute1, extensionattribute2 $groups = $users | Group -Property extensionattribute1 $groups | select Count, Name | Export-Csv out.csv -notypeinformation