Jump to content

Stupid, weird script error, but script works anyway?


Recommended Posts

Posted

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:

 

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:

 

 

$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\groupmembersimport2.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\groupmembersimport2.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 weeks later...
Posted

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")

Posted
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:

 

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:

 

 

$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\groupmembersimport2.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\groupmembersimport2.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/library/ee617210.aspx

 

Steve

Posted

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... :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...