I'm currently trying to retrieve a listing of all security groups in an OU, count the total members assigned, and also count accounts in a group that are inactive (either locked out or disabled)
My current code does that(I think) but it currently calls the Get ADGroupmember cmdlet twice which seems to be inefficient. My problem is, I am not yet skilled enough to pull multiple values from the same query, nor am I skilled enough to know if it is even possible to pull two types of info in one query like that
My code is:
PowerShell Code
Double-click the code block to select all.Import-Module ActiveDirectory $groups = Get-ADGroup -f * -searchbase 'MY OU HERE' foreach ($group in $groups) { $groupname=($group.name) $membercount=@(Get-ADGroupMember $groupname).count $inactive=@(Get-ADGroupMember $groupname | Get-ADUser -Property * | where {$_.lockedout -OR $_.Enabled -Like 'false'}).count $strdone = $groupname +','+ $membercount +','+ $inactive Add-content c:\outputfiles\CountofUsersinEachGroup.txt -value $strdone }I would appreciate it if someone could show me how to combine queries to pull multiple values from the same cmdlet (if it's even possible in this case)