So here is the major problem. I was recently tasked with creation of a script to get a user count for every group, and list that count, per group, all groups in a specific OU in AD.
I have created two solutions so far, but can't seem to combine the two. My knowledge of PowerShell is rather lacking.
Script 1 Lists number of active, disabled, and total users in a specific OU path:
Import-Module activeDirectory Get-ADOrganizationalUnit -filter * -SearchBase 'OU=ENDOU,OU=MIDOU,OU=SOURCEOU,DC=DOMAIN,DC=local' | foreach { $users=Get-ADUser -filter * -searchbase $_.distinguishedname -ResultPageSize 2000 -resultSetSize 500 -searchscope Onelevel $total=($users | measure-object).count New-Object psobject -Property @{ OU=$_.Name; TotalUsers=$Total; Enabled=$Enabled; Disabled=$Disabled } } | Export-Csv C:\temp\Users1.csv
Script two lists every group in that OU path:
Import-Module activeDirectory Get-ADOrganizationalUnit -filter * -SearchBase 'OU=ENDOU,OU=MIDOU,OU=SOURCEOU,DC=DOMAIN,DC=local' | foreach { get-adobject -Filter 'ObjectClass -eq "group"' }
Does anyone know if it is possible to do what is requested, as in, script to list ever group in an OU path, and also display number of enabled users per group for every OU?
Thanks in advance for any help you guys can suggest, thanks.