mercredi 17 août 2016

How to count the result of a if loop within foreach loop

Is there a better way to be able to count the amounts of empty groups than using this method and then calling $count + 1 for each result? I tried to mess around with $123.count but it kept returning 0

$Groups = Get-ADGroup -Properties * -Filter * | where { $_.Members.Count -eq 0}
$123= Foreach($G In $Groups)
{
    $Membership = Get-ADGroupMember -Identity $G.Name
    If($Membership.count -eq 0){
    $Count = $count + 1
    }

}

Aucun commentaire:

Enregistrer un commentaire