Is there a way pull users with their name, email I’d but also with their group menebership using power shell

Perumal, Janakiraman 241 Reputation points
2021-04-30T16:51:47.663+00:00

Hi All,

I am trying to extract the list of users along with their group, mail etc using powershell. Is there way to get this information from cmdlet?

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,094 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 94,196 Reputation points MVP
    2021-04-30T19:38:31.533+00:00

    Hi @Perumal, Janakiraman ,

    maybe this is helpful:

    Import-Module ActiveDirectory  
    $users = "mmouse","ppan1234"  
    $Table = @()  
    foreach ($user in $users) {  
        $grp = ""  
        $Row = [ordered]@{SamAccountName = "";DisplayName = "";Email = "";Groups = ""}  
        $a = Get-AdUser -Identity $user -Properties *  
        $groups = $a.MemberOf  
        foreach ($g in $groups) {  
            $b = Get-ADGroup $g  
            $grp += $b.Name + ","  
        }  
        $grp = $grp.Substring(0, $grp.Length - 1)  
        $row.SamAccountName = $a.SamAccountName  
        $row.DisplayName = $a.DisplayName  
        $row.Email = $a.EmailAddress  
        $row.Groups = $grp  
        $objRow = New-Object PSObject -Property $row  
        $Table += $objRow  
    }  
    $Table  
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


0 additional answers

Sort by: Most helpful