Forum Discussion

Test SharePoint's avatar
Test SharePoint
Brass Contributor
Oct 12, 2019
Solved

Trying to add multiple users to distribution group and getting error: Cannot validate argument

I am trying to add multiple users in a distribution Group.

All users are in cloud.

I have a CSV which has the following columns :

DisplayName, Alias, PrimarySmtpAddress

 

I am trying the following script:

 

$Userslist = Import-CSV c:\users\user\ab.csv
ForEach ($User in $Userslist)
{
Add-DistributionGroupMember -Identity "Office" -Member $User.PrimarySmtpAddress
}

 

I am getting the following error:

Cannot validate argument on parameter 'Member'. The argument is null. Provide a valid value for the argument, and then try running the command again.
+ CategoryInfo : InvalidData: (:) [Add-DistributionGroupMember], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Add-DistributionGroupMember
+ PSComputerName : outlook.office365.com

 

any help would be appreciated

  • DanielNiccoli's avatar
    DanielNiccoli
    Steel Contributor

    Test SharePointSomething breaks during import. "Cannot validate argument on parameter 'Member'. The argument is null." Null means that it couldn't parse the csv, otherwise it would be an empty string.

     

    Have you confirmed that the import actually works?

     

    $Userslist = Import-CSV c:\users\user\ab.csv
    
    $Userlist
    
    $Userlist[0]
    • Test SharePoint's avatar
      Test SharePoint
      Brass Contributor

      DanielNiccoli : thanks for your reply. I tried the above command and get this:

       

      Cannot index into a null array.
      At line:1 char:1
      + $Userlist[0]
      + ~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : NullArray

Resources