Forum Discussion

Catarinagm's avatar
Catarinagm
Copper Contributor
Aug 22, 2022
Solved

See groups menbership of a list of users

Hello, I'm trying to get a list from all groups that a user is part of, on a single file (DL, Teams groups, ...)   This is what I'm doing:   Connect-AzureAD $Users=Get-Content -Path "C:\Temp...
  • raindropsdev's avatar
    Aug 22, 2022

    Catarinagm

     

    Hi,

     

    The easy answer is that you're trying to get the UserPrincipalName of the Group rather than the user, which returns null because the group doesn't have a UserPrincipalName.

    As the variable $_. has already been overwritten by Get-AzureAdUsermembership you can't really reference back.

     

    I have written a Powershell script that would do the job and shared it on Github:

    https://github.com/Raindrops-dev/RAIN-TechCommunityContributions/blob/main/Get-AzureAdGroupMembership.ps1

     

    Check it out and let me know if it fits your requirements.

     

    EDIT: Apparently I was too slow and LainRobertson already came with a more modern solution!