Expand Groups recursively using Graph API

No biggie but in case it saves someone a bit of Googling… :) Had a need to expand a group recursively so I created the following function:

Update 13th July 2023: Fixed a typo in the above code.

Also, the Get-MgGroupTransitiveMember cmdlet is a good in-built replacement for the above. It lists recursive members too. By default it returns users and groups, so to filter for just users like above do the following: