@Vij, Thanks for posting in Q&A. Based on my researching, I didn't find the script to do this. But I find we can check it via audit log. When a group is added into the device configuration profile assignment or app assignment. it will be recorded.
https://learn.microsoft.com/en-us/mem/intune/fundamentals/monitor-audit-logs
Hope the above information can help.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.