none
Powershell script to find group membership of list of users from AD. RRS feed

  • Question

  • Hi,

    I got a list of 340 users (got their ad login names) and I would like to get their group membership.

    All login names are in csv file, one below other (import from xls). would like to have output as :

    paul: grp1, grp2, grp3

    Peter: grp2, grp3, grp7

    I got single user query as:

    (get-aduser -identity "loginname" -properties memberof |select-object memberof).memberof > C:\temp\grp.csv

    I don't know how to replace "loginname" with "list of loginnames" ,so that I don't have to run query 340 times.

    Do you have any powershell script to get this kind of output?

    Thx.

    S

    • Moved by Bill_Stewart Saturday, January 17, 2015 8:16 PM Poor quality question/shows no research effort
    Friday, November 21, 2014 5:06 AM

All replies

  • Hi,

    If you have a csv that looks like this:

    Name,
    Loginname1
    Loginname2

    Use the following:

    $csv = Import-CSV -Path "C:\grp.csv"
    
    foreach($line in $csv)
    {
    (get-aduser -identity $($line.name) -properties memberof |select-object memberof).memberof
    }


    Nico Martens
    SharePoint/Office365/Azure Consultant

    Friday, November 21, 2014 6:24 AM
  • $($line.name)  -  always unnecessary except in strings. 

    Use $line.name


    ¯\_(ツ)_/¯

    Friday, November 21, 2014 9:01 AM