Hello,
I am not sure if this is the correct approach, nor if there are better options than this.
Still looking at the article below, there seems to be a community PowerShell module that allows you to create and manage SCOM Groups from a PS Script:
https://www.cloudsma.com/2018/01/automate-scom-group-creation/
Having that, you just need your PowerShell commands to extract collection members from MECM (maybe this - https://learn.microsoft.com/en-us/powershell/module/configurationmanager/get-cmcollectionmember?view=sccm-ps)
I hope it helps!
BR,
George