none
Populate Group with CSV file

    Question

  • i've worked on this from multiple people from this forum but we cannot get it right. anyone think they have an idea? 
    the goal is to populate a group with a csv. we got this but it doesnt work right 
    $File = "C:\csv\file.csv"
    $Group = Get-QADGroup 'cn=Test Group,OU=Administration,OU=IT,OU=Test,OU=Groups,DC=CD1,DC=BCU,DC=EDU'
    Import-Csv -Path $File | ForEach-Object {
        Add-QADGroupMember $Group.DN -Member $_.DN
    }

    bradley Wyatt

    Tuesday, May 08, 2012 7:39 PM

Answers

All replies

  • Add-QadGroupMember: cannot validate argument on parameter 'Member'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again 

    bradley Wyatt

    Tuesday, May 08, 2012 7:45 PM
  • The error message seems perfectly clear to me.

    Please copy and paste the exact output of this command:

    get-content c:\csv\file.csv

    Bill

    Tuesday, May 08, 2012 7:52 PM
  • It finally reads all the suers within the csv !! but I get this now

     Get-QADGroup : A referral was returned from the server. (Exception from HRESULT: 0x8007202B)
    At C:\s4.ps1:2 char:22
    + $Group = Get-QADGroup <<<<  'OU=Administration,OU=IT,OU=Test,OU=Groups,DC=CD1,DC=BCU,DC=EDU'
        + CategoryInfo          : NotSpecified: (:) [Get-QADGroup], COMException
        + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Quest.ActiveRoles.ArsPowerShellSnapIn.Powers
       hell.Cmdlets.GetGroupCmdlet

    Import-Csv : Cannot bind argument to parameter 'Path' because it is null.
    At C:\s4.ps1:3 char:17
    + Import-Csv -Path <<<<  $File | ForEach-Object {
        + CategoryInfo          : InvalidData: (:) [Import-Csv], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ImportCsvCo
       mmand
    Changes the OU path for security purposes 


    bradley Wyatt

    Tuesday, May 08, 2012 7:56 PM
  • Hi,

    For your first command, take a look at what you are running:

    Get-QADGroup 'OU=Administration,OU=IT,OU=Test,OU=Groups,DC=CD1,DC=BCU,DC=EDU'

    That's the name of an OU, isn't it?

    For the second error, the $File variable you are using is null (hence the error).

    Bill

    Tuesday, May 08, 2012 8:08 PM
  • I thought so too, I listed it backwards and forwards just in case but get the same error.  had to change a lot in the pic for security reasons

    bradley Wyatt

    Tuesday, May 08, 2012 8:22 PM
  • Hi,

    Don't be the person that just wants to know a magic phrase to type without really understanding why the magic phrase works.

    1. Get-QADGroup retrieves a group. (Hence the name.) Thus: You can't specify the name of an OU. You must specify the name of a group.
    2. A parameter is an item on the command line that starts with a dash, such as -Path, and the parameter's argument is the data after a parameter ($File). If you use "Import-Csv -Path $File" and PowerShell tells you the Path parameter's argument is null, that means the $File variable is null or empty.

    HTH,

    Bill

    Tuesday, May 08, 2012 8:28 PM
  • Hi,

    Learning is good, and we all start somewhere. I recommend starting here:

    http://technet.microsoft.com/en-us/scriptcenter/dd793612

    Once you begin understanding the fundamentals, then you can start moving on to more advanced topics.

    Bill

    Tuesday, May 08, 2012 8:47 PM
  • I got it to work, but it says cannot bind Argument to parameter 'Path' because it is null. I think it cannot read it out correctly

    bradley Wyatt

    Tuesday, May 08, 2012 8:48 PM
  • Hi,

    As I explained earlier, that error message means that the $File variable is null or empty.

    Bill

    Tuesday, May 08, 2012 8:49 PM
  • Yep I know what Null means. Was wondering if anyone had any ideas why. it's filled with about 400 objectnames and SAMAccountNames Thank for helping me understand PowerShell

    bradley Wyatt

    Tuesday, May 08, 2012 8:54 PM
  • Hi,

    There is not any way for us to troubleshoot why the $File parameter you are using is null unless you post the script you are using. (Remember: We can't see your screen.)

    Bill

    Tuesday, May 08, 2012 9:00 PM
  • I use this to populate the .csv with users from an OU 

    $OU = "cd1.ds1.bcu.edu/Administration/IT/Users"
    $FilePath = "C:\csv\file.csv" 
    Get-QADUser -SearchRoot $OU `
    | select-Object name, SamAccountName `
    | Export-Csv $FilePath

    and then run this to try and populate another group from that .csv

    get-content c:\csv\file.csv
    $Group = Get-QADGroup 'CN=Test Group,OU=Groups,OU=Test,OU=IT,OU=Administration,IT,DC=CD1,DC=BCU,DC=EDU'
    Import-Csv -Path $File | ForEach-Object {
        Add-QADGroupMember $Group.DN -Member $_.DN
    }

    Changed OU string for security


    bradley Wyatt

    Tuesday, May 08, 2012 9:03 PM
  • The term -Member $_.DN implies a heading line in the csv file that defines a field labeled "DN". There may be lots of stuff in the file, but if there is no "DN" field, then $_.DN will be Null.


    Richard Mueller - MVP Directory Services

    Tuesday, May 08, 2012 9:03 PM
  • Hi,

    Take another look at your code (unless you're not posting what you're actually using!).

    get-content c:\csv\file.csv
    $Group = Get-QADGroup 'CN=Test Group,OU=Groups,OU=Test,OU=IT,OU=Administration,IT,DC=CD1,DC=BCU,DC=EDU'
    Import-Csv -Path $File | ForEach-Object {
        Add-QADGroupMember $Group.DN -Member $_.DN
    }
    

    You are not defining the $File variable. Hence the error.

    Bill

    Tuesday, May 08, 2012 9:13 PM
  • oh wow! never noticed that! I defined $File as
    $File = 'C:\csv\file.csv 
    Where the csv is located and then when it looks at $file when i run it i get back to "cannot validate argument on parameter 'Member'. The argument is null or empty

    bradley Wyatt

    Tuesday, May 08, 2012 9:20 PM
  • OK, as a followup from our twitter chat. ;)

    Your $FilePath will probably look like that:

    "Name","SamAccountName"

    "Foo","Bar"

    Clearly, once you import this file there won't be any "DN" to play with.

    Luckily for you - -Member parameter will do just fine with sAMAccountName, so just use this property from resulting csv instead of non-existend DN property:

    $File = "C:\csv\file.csv"
    $Group = Get-QADGroup TestGroup
    Import-Csv -Path $File | ForEach-Object {
        Add-QADGroupMember $Group.DN -Member $_.sAMAccountName
    }

    HTH
    Bartek

    Tuesday, May 08, 2012 9:23 PM
  • For $group = Get-QADGroup TestGroup I changed it to the location where my CN is located at. 

    bradley Wyatt

    Tuesday, May 08, 2012 9:32 PM
  • Fixed one issue (I hope) but caused another... ;)

    Get-QADGroup code may be wrong, I just left it there to keep code complete.
    There was nothing wrong with your code around Get-QADGroup IMO (previously cmdlet was not complaining about Identity parameter, and this is positional: $Group.DN in your case)

    The only change (other than making sure you use correct variable name ;) ) is to replaced $_.DN (that IMO won't show up in file you've created) with $_.SamAccountName (that exists in CSV and should be sufficient to identify -Member).

    HTH
    Bartek

    Tuesday, May 08, 2012 9:38 PM
  • if i run 
    get-content c:\csv\file.csv
    $File = "C:\csv\file.csv"
    $Group = Get-QADGroup 'CN=Test Group,OU=Groups,OU=Test,OU=IT,OU=Administration,IT,DC=CD1,DC=BCU,DC=EDU'
    Import-Csv -Path $File | ForEach-Object {
        Add-QADGroupMember $Group.DN -Member $_.sAMAccountName
    }

    I get cannot bind argument to parameter 'Path' because it is null error

    if i run 

    get-content c:\csv\file.csv
    $File = "C:\csv\file.csv"
    $Group = Get-QADGroup 'CN=Test Group,OU=Groups,OU=Test,OU=IT,OU=Administration,IT,DC=CD1,DC=BCU,DC=EDU'
    Import-Csv -Path $File | ForEach-Object {
        Add-QADGroupMember $Group.DN -Member $_.DN
    }

    I get cannot validate argument on parameter 'Member'. The argument is null or empty. error. ugh


    bradley Wyatt

    Tuesday, May 08, 2012 9:52 PM
  • Simplify to debug:

    $g=Get-QADGroup TestGroup
    Import-Csv "C:\csv\file.csv" |
         ForEach-Object {
              Write-Host "adding $($_,samaccountname)"
              Add-QADGroupMember $g.DN -Member $_.sAMAccountName
         }

     


    ¯\_(ツ)_/¯

    Tuesday, May 08, 2012 10:02 PM
  • This is actually the way I would do it as it eliminates many potential issues.

    get-qadgroup mytest|Add-QADGroupMember -member (Import-csv file.csv|%{$_.samaccountname})

    This will bulk import into the group returned by Get-QADGroup.


    ¯\_(ツ)_/¯

    Tuesday, May 08, 2012 10:09 PM
  • the previous one didnt work, how do i format the one above

    bradley Wyatt

    Wednesday, May 09, 2012 3:50 PM
  • the previous one didnt work, how do i format the one above

    bradley Wyatt

    Sorry but your question doesn't make much sense.  What do you mean by 'format'.

    There is no reason for the last one to not work.  It is identical to the previous one technically and logically.


    ¯\_(ツ)_/¯

    Wednesday, May 09, 2012 3:59 PM
  • Hi bradley Wyatt,

    Sorry to sound like a broken record, but we've been through this before. Remember--we cannot see your screen. You need to put enough information (start with the exact command you are using and the exact error messages) in your post so we can try to help. Otherwise, we will have to guess and ask you for more information. You are only slowing your own progress by not posting any information.

    Bill

    Wednesday, May 09, 2012 4:03 PM
  • Marking as answered since we seem to have it answered in another thread (that would seem to be a duplicate of this one):

    http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/1d770917-b36a-4f44-a80f-89954aab04ce

    Bill

    Wednesday, May 16, 2012 4:59 PM