none
PowerShell Hashtables RRS feed

  • Question

  • Hi All,

    i really need some help. I am pretty new to powershell.  Trying to solve a very manual task. for adding new hires  to adgroups. 

    because our new hires dept and title depend on what active directory group he/she will be added to. i decide to create two hash table with key values dept = title 

    groups =  name of the groups. 

    i am also importing the all new hires from a csv file. anyway came some be kind of enough to check out my script and tell me what i am doing wrong. i keep getting errors every time i try to run the script.

    $Title = @()
    if ($dept -like "Name,") { $Title -like "Name" }
    if ($dept -like "Name") { $Title -like "name" }
    $group = @()
    if ($Title -like "name") { $groups += "groupname","groupname","groupname","groupname","groupname"}
    if ($Title -like "name") { $groups += ""groupname","groupname","groupname","groupname","groupname"}
     $names = import-csv c:\filename.csv
     
     ForEach ($name in $names) {
     $SamAccountName = $_."SamAccountName"
      Add-ADGroupMember $groups $name;

    Thank you all for reading my post!


    PS

    Thursday, May 16, 2019 4:27 PM

All replies

  • There are no hash tables in your example.  When posting you need to post the exact error.

    How to ask questions in a technical forum

    Microsoft Virtual   Academy - Getting Started with Microsoft PowerShell


    \_(ツ)_/

    Thursday, May 16, 2019 4:43 PM
  • Hi,

    I have my hashtables in the example i posted.  

    sorry for not posting the error. 

    Add-ADGroupMember : Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and then try running the 
    command again.
    At line:11 char:23
    +     Add-ADGroupMember $groups $name;
    +                       ~~~~~~~
        + CategoryInfo          : InvalidData: (:) [Add-ADGroupMember], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember


    PS

    Thursday, May 16, 2019 4:54 PM
  • There are no hash tables in your example.  What is it that you are calling a hash table?

    The error is telling you that you are not using the command correctly.

    Please read the help for the command:

    help Add-AdGroupMember -online

    Learning basic PowerShell will help you to write a script.  Guessing will not help you.

    Microsoft Virtual   Academy - Getting Started with Microsoft PowerShell


    \_(ツ)_/

    Thursday, May 16, 2019 4:57 PM