none
Adding multiple users to a group RRS feed

  • Question

  • Hi everyone,

    I am new to scripting and please need some help

    I have an AD group called SGG_ARC_CTX_SIIED and and trying to add users to this group from a csv file

    The CSV file is formatted as follows

    member

    ARC\AaronG
    ARC\AdamD
    ARC\AlanMoo
    ARC\Anahitad
    ARC\AndrewK
    ARC\AndySa
    ARC\AnjaniG

    $import = Import-Csv c:\psinput\siied.csv
    foreach ($user in $import) {add-QADGroupMember -identity arc\SGG_ARC_CTX_SIIED -member $_.member}
    I have quest tools installed and what I am trying to achieve is for the foreach to use the names in the csv file to populate the -member variable. I am having trouble understanding when to use the curly brackets and where so any help would be greatfully appreciated. Dan

    Wednesday, April 16, 2014 12:16 AM

Answers

  • Hi Dan,

    I don't have the Quest tools to test with, but if they're like the standard AD module, Add-QAGroupMember won't like the format of domain\username. Give this a try (I've included an example that works with the AD module as well):

    # Quest tools
    # foreach loop
    $import = Import-Csv c:\psinput\siied.csv
    
    foreach ($user in $import) {
    
        Add-QADGroupMember -Identity SGG_ARC_CTX_SIIED -Member ($user.member.Split('\'))[1]
    
    }
    
    
    # Active Directory module
    # ForEach-Object loop
    Import-Csv c:\psinput\siied.csv | ForEach {
    
        Add-ADGroupMember -Identity SGG_ARC_CTX_SIIED -Members ($_.member.Split('\'))[1]
    
    }


    Don't retire TechNet! - (Don't give up yet - 12,830+ strong and growing)

    • Proposed as answer by jrv Wednesday, April 16, 2014 2:25 AM
    • Marked as answer by Bill_StewartModerator Tuesday, May 20, 2014 4:22 PM
    Wednesday, April 16, 2014 1:51 AM

All replies

  • Hi Dan,

    I don't have the Quest tools to test with, but if they're like the standard AD module, Add-QAGroupMember won't like the format of domain\username. Give this a try (I've included an example that works with the AD module as well):

    # Quest tools
    # foreach loop
    $import = Import-Csv c:\psinput\siied.csv
    
    foreach ($user in $import) {
    
        Add-QADGroupMember -Identity SGG_ARC_CTX_SIIED -Member ($user.member.Split('\'))[1]
    
    }
    
    
    # Active Directory module
    # ForEach-Object loop
    Import-Csv c:\psinput\siied.csv | ForEach {
    
        Add-ADGroupMember -Identity SGG_ARC_CTX_SIIED -Members ($_.member.Split('\'))[1]
    
    }


    Don't retire TechNet! - (Don't give up yet - 12,830+ strong and growing)

    • Proposed as answer by jrv Wednesday, April 16, 2014 2:25 AM
    • Marked as answer by Bill_StewartModerator Tuesday, May 20, 2014 4:22 PM
    Wednesday, April 16, 2014 1:51 AM
  • Works great thanks . I always have difficulty with which brackets to use to call the variable once you have doen the foreach . I guess in that import file there could be other column headers, whihc is why you use the $user.member. I thinks its slowly starting to sink in. :-)

    Wednesday, April 16, 2014 2:42 AM