Pulling back a count of direct group members where objectClass is group

hi @tbrain1978 and welcome to the forum.
First things first if you wouldn’t mind editing your post and formatting your code as “Preformatted text” that would make it a lot easier for people to help.
Guide to Posting Code

This isn’t an answer to your question but a bit of constructive criticism. You’re declaring an empty array and then using the += operation to add objects to that array. It would be less work, and faster, to capture the output of the operation with your array definition like this:

$Groups = Get-AdGroupMember <something>

Get-AdGroupMember specifically returns the members of a given group, then it looks like we’re piping that to Where-Object to filter the output to only include groups that are a member of that provided group. Those go in to our $Groups variable.

Later when you’re defining $DirectGroupsCount there shouldn’t be any need to pipe it to Where-Object again since $Groups should only contain group objectclass objects anyway.
Unfortunately, if there’s only one group object as a member of a group your $Groups variable wouldn’t be an array with a ‘count’ property unless you did it like you have in your code. How I would handle this is this way:

[Array]$Groups = Get-ADGroupMember -Identity $GroupName | Where-Object {$_.Objectclass -eq "Group"}
Write-Host $Groups -ForegroundColor Magenta
Write-Host "Direct Groups Count: $($Groups.count)" -ForegroundColor Green

the [Array] syntax is strongly typing the variable $Groups to make sure it’s always an array, even if it only contains one thing. That way the count property will exist.