none
How to get users of AD from a txt.file list?

    Domanda

  • Hello,

    I'm trying to make a list of users from a specific list of AD-groups that is in a txt.file using PowerShell.

    For example I have these groups in a txt.file:

    ACBSQL01.AUDT.GG
    BTTSQL05.audt.gg
    CTJBEQ01.Audt.GG
    and I want to list the users of these groups with PowerShell.

    I'd tried the code below, but it's not working.

    Import-Module ActiveDirectory
    $File = Get-Content C:\Users\RSOUZA9\LocalData\Groups.txt |  ForEach-Object {Get-ADGroupMember -Identity $_}

    Thank's!

    martedì 26 giugno 2012 13:38

Risposte

  • Your examples are not valid group names. They should either be the sAMAccountNames of the groups (pre-Windows 2000 names), or the distinguished names. I suspect the file should be similar to:


    cn=ACBSQL01,dc=AUDT,dc=GG
    cn=BTTSQL05,dc=AUDT,dc=GG
    cn=CTJBEQ01,dc=AUDT,dc=GG

    -----

    but even this looks suspicious, as it shows all groups in the root of the domain audt.gg. Each name either must be a distinguished name, similar to "cn=Test group,ou=Sales,ou=West,dc=MyDomain,dc=com", or the "pre-Windows 2000" name, similar to "MyGroup" (without the quotes).


    Richard Mueller - MVP Directory Services

    martedì 26 giugno 2012 17:34

Tutte le risposte

  • Your code should work.  What error are you getting?

    Grant Ward, a.k.a. Bigteddy

    martedì 26 giugno 2012 13:53
  • Try this:

    Get-Content C:\Users\RSOUZA9\LocalData\Groups.txt |  Get-ADGroupMember

    Or this one:

    Get-ADGroupMember -Identity (Get-Content C:\Users\RSOUZA9\LocalData\Groups.txt)
    Karl

    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

    martedì 26 giugno 2012 13:54
  • Thank's Karl, but I received the following error using your first suggest:

    "Get-ADGroupMember : The input object cannot be bound to any parameters for the command either because the command does
    not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input."

    martedì 26 giugno 2012 14:07
  • Bigteddy,

    The error that I'm getting is:

    Get-ADGroupMember : Cannot bind parameter 'Identity' to the target. Exception setting "Identity": "Cannot validate argu
    ment on parameter: 'Identity'. The argument is null or empty. Supply an argument that is not null or empty and then try
     the command again."

    martedì 26 giugno 2012 14:08
  • I would suspect the content of your text file.  Both of Karl's suggestions should have worked, as should your original code.

    Grant Ward, a.k.a. Bigteddy

    martedì 26 giugno 2012 14:14
  • I would leave the variable definition ($File =) off the original script when passing it through the pipeline....

    I question the validity of the input data too.

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

    martedì 26 giugno 2012 15:39
  • Your examples are not valid group names. They should either be the sAMAccountNames of the groups (pre-Windows 2000 names), or the distinguished names. I suspect the file should be similar to:


    cn=ACBSQL01,dc=AUDT,dc=GG
    cn=BTTSQL05,dc=AUDT,dc=GG
    cn=CTJBEQ01,dc=AUDT,dc=GG

    -----

    but even this looks suspicious, as it shows all groups in the root of the domain audt.gg. Each name either must be a distinguished name, similar to "cn=Test group,ou=Sales,ou=West,dc=MyDomain,dc=com", or the "pre-Windows 2000" name, similar to "MyGroup" (without the quotes).


    Richard Mueller - MVP Directory Services

    martedì 26 giugno 2012 17:34