Another problem with this code: if a group has only one member method Count resolves me no information (not null, nothing).
This is a Powershell gotcha, which you can read about in the in the free ebook The Big Book of PowerShell Gotchas in the above link. Basically, if there is a single object, Powershell is doing a conversion that breaks the Count property. The fix is simple, and I try to do it in all of my code even though it’s supposed to be fixed. For instance, the variable is $GroupMemberList, so if you wrap it in an array like so because the Count is returning from an array object:
@($GroupMemberList).Count
There are also a lot of pre-built report you can try as well that will give a ton of information: