This script finds all AD groups beginning with ‘MSI – ‘ or ‘App-V – ‘ and returns the number of members it contains.  Note that it doesn’t recurse nested groups!  It then outputs the results to a CSV file.

$csvPath = "C:\Alkane\AlkaneGroups.csv"

"Group,Count" | Out-File -filepath $csvPath -Append -encoding ASCII

$groups = Get-ADGroup -filter {(name -like "MSI - *") -or (name -like "App-V - *")}
foreach($group in $groups){
	$countUser = (Get-ADGroup $group -Properties *).member.count
	Write-Host "The group $($group.Name) has $countUser user(s)."
	"""$($group.Name)"",$countUser" | Out-File -filepath $csvPath -Append -encoding ASCII
}

 

Count members of an AD Group and write to CSV
Comments have now been disabled. If you have a question to ask about this post please ask the community!