PowerShell Exchange Online does not working properly

Copper Contributor

Recently one meeting asked me to create a script to find the distribution list group which have one member. In a real scenario, I have lots of distribution lists that have one member.

as you can see in the picture ;

houmanalv_0-1708444901902.png

 

when I try to write a command it returns nothing in Powershell

 

houmanalv_1-1708445012215.png

houmanalv_2-1708445172831.png

 

the command perfectly works for two, three,... member groups even zero members. I believe there is a bug in the PowerShell code.

 

 

1 Reply
The cmdlet works fine, it's you example that needs fixing :)

When the cmdlet returns a single object as output, it is of the PSObject type, and does not have a property called "count". Instead, it will represent the ReducedRecipient object returned by the cmdlet (i.e. the actual member), and reflect its own properties. And as you can see in your second example, you can pass the output against the Measure-Object cmdlet to get you the count, safely.

If you want to be able to use .count with your first example, make sure you are storing the output as list/array:

@(Get-DistributionGroupMember hsbc_support).count