+ Post New Thread
Results 1 to 4 of 4
Scripts Thread, Stupid, weird script error, but script works anyway? in Coding and Web Development; Bit of an odd one today! I have knocked up a script to add users to groups in AD, based ...
  1. #1

    Miscbrah's Avatar
    Join Date
    Dec 2011
    Posts
    1,010
    Thank Post
    285
    Thanked 298 Times in 180 Posts
    Rep Power
    124

    Stupid, weird script error, but script works anyway?

    Bit of an odd one today!

    I have knocked up a script to add users to groups in AD, based on a .csv file of their usernames and group names, as in:

    Code:
    Group,Member
    SLT,Bob Jones
    SLT,John Jones
    SLT,Indiana Jones
    Teachers,Spike Jones
    Teachers,Skinand Jones

    So, with that all in mind I've knocked up this script:


    Code:
    $path = "c:\adgroups\groupsandmembersmaster.csv"
    $csv = Import-csv -path $path
    foreach($line in $csv)
    {
       Add-ADGroupMember -Identity $line.Group -Member $line.Member
    }
    
    Write-Host "Press any key to continue..."
    
    $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

    My thinking being it'll run everything and then ask me for a key press when done. Thing is, it DOES put the people in the right groups, but throws up the following error messages over and over and over (lots of red writing in that Powershell window!):


    ...
    Add-ADGroupMember : Cannot validate argument on parameter 'Members'. The argume
    nt is null or empty. Supply an argument that is not null or empty and then try
    the command again.
    At C:\Users\Administrator.LHS\Desktop\groupmembersimp ort2.ps1:5 char:51
    + Add-ADGroupMember -Identity $line.Group -Member <<<< $line.Member
    + CategoryInfo : InvalidData: ( [Add-ADGroupMember], ParameterB
    indingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ
    eDirectory.Management.Commands.AddADGroupMember

    Add-ADGroupMember : Cannot validate argument on parameter 'Members'. The argume
    nt is null or empty. Supply an argument that is not null or empty and then try
    the command again.
    At C:\Users\Administrator.LHS\Desktop\groupmembersimp ort2.ps1:5 char:51
    + Add-ADGroupMember -Identity $line.Group -Member <<<< $line.Member
    + CategoryInfo : InvalidData: ( [Add-ADGroupMember], ParameterB
    indingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ
    eDirectory.Management.Commands.AddADGroupMember
    ...


    Got no idea why, seeing as it is in fact doing what it should do, but it spits out those errors on and on until I ctrl+c the window.

    Any clues what it doesn't like? I'm not sure I get the meaning of it there!

  2. #2
    ascott2's Avatar
    Join Date
    Nov 2007
    Posts
    185
    Thank Post
    18
    Thanked 39 Times in 31 Posts
    Rep Power
    21
    I have always had some quirky issues using foreach($line in $csv). Not sure if this will solve the issue, but couldn't hurt giving it a try

    $path = "c:\adgroups\groupsandmembersmaster.csv"
    Import-csv -path $path |
    foreach
    {
    Add-ADGroupMember -Identity $_.Group -Member $_.Member
    }

    Write-Host "Press any key to continue..."

    $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

  3. #3

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,762
    Thank Post
    354
    Thanked 533 Times in 498 Posts
    Rep Power
    182
    Quote Originally Posted by Miscbrah View Post
    Bit of an odd one today!

    I have knocked up a script to add users to groups in AD, based on a .csv file of their usernames and group names, as in:

    Code:
    Group,Member
    SLT,Bob Jones
    SLT,John Jones
    SLT,Indiana Jones
    Teachers,Spike Jones
    Teachers,Skinand Jones

    So, with that all in mind I've knocked up this script:


    Code:
    $path = "c:\adgroups\groupsandmembersmaster.csv"
    $csv = Import-csv -path $path
    foreach($line in $csv)
    {
       Add-ADGroupMember -Identity $line.Group -Member $line.Member
    }
    
    Write-Host "Press any key to continue..."
    
    $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

    My thinking being it'll run everything and then ask me for a key press when done. Thing is, it DOES put the people in the right groups, but throws up the following error messages over and over and over (lots of red writing in that Powershell window!):


    ...
    Add-ADGroupMember : Cannot validate argument on parameter 'Members'. The argume
    nt is null or empty. Supply an argument that is not null or empty and then try
    the command again.
    At C:\Users\Administrator.LHS\Desktop\groupmembersimp ort2.ps1:5 char:51
    + Add-ADGroupMember -Identity $line.Group -Member <<<< $line.Member
    + CategoryInfo : InvalidData: ( [Add-ADGroupMember], ParameterB
    indingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ
    eDirectory.Management.Commands.AddADGroupMember

    Add-ADGroupMember : Cannot validate argument on parameter 'Members'. The argume
    nt is null or empty. Supply an argument that is not null or empty and then try
    the command again.
    At C:\Users\Administrator.LHS\Desktop\groupmembersimp ort2.ps1:5 char:51
    + Add-ADGroupMember -Identity $line.Group -Member <<<< $line.Member
    + CategoryInfo : InvalidData: ( [Add-ADGroupMember], ParameterB
    indingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ
    eDirectory.Management.Commands.AddADGroupMember
    ...


    Got no idea why, seeing as it is in fact doing what it should do, but it spits out those errors on and on until I ctrl+c the window.

    Any clues what it doesn't like? I'm not sure I get the meaning of it there!
    Isn't it "Members"?

    Add-ADGroupMember -Identity $line.Group -Member $line.Member

    -Member <-

    Try:

    Add-ADGroupMember -Identity $line.Group -Members $line.Member ?

    http://technet.microsoft.com/en-us/l.../ee617210.aspx

    Steve

  4. #4

    Miscbrah's Avatar
    Join Date
    Dec 2011
    Posts
    1,010
    Thank Post
    285
    Thanked 298 Times in 180 Posts
    Rep Power
    124
    Thanks! No it doesn't like 'members' and that's BLOODY weird because I thought that when I knocked the script up. Oh well...

    Strangely enough it seems to have done what I wanted it to do anyway, and breaking my source .csv into smaller more manageable sections (one group or 50-odd users at a time) seemed to make it happier also.

    Meh, another one I'll just chalk up to paranormal activity...



SHARE:
+ Post New Thread

Similar Threads

  1. Weird spooler error
    By danrhodes in forum Windows
    Replies: 4
    Last Post: 14th January 2010, 10:51 AM
  2. Replies: 1
    Last Post: 4th September 2008, 07:31 PM
  3. Replies: 14
    Last Post: 27th March 2008, 05:57 PM
  4. Weird/Annoying error
    By Gatt in forum Wireless Networks
    Replies: 2
    Last Post: 30th June 2006, 05:41 AM
  5. Weird SMB Error
    By MouseAT in forum Windows
    Replies: 18
    Last Post: 24th March 2006, 02:29 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •