Zend certified PHP/Magento developer

Unable to add members to a mail-enabled security group using PowerShell Script

I am connected to Exchange Online via PowerShell and I’m trying to add a bulk list of members via a CSV file. The below script is what I have used and the error keeps pointing back to the member argument is null. I used a Write-Host to verify that the columns in the CSV file was actually read (originally it was trying to read the entire column as one member)

Import CSV file

$users = Import-Csv -Path "C:ScriptsCode2_list.csv"

Mail-enabled security group name

$mailEnabledSecurityGroup = "Code2_License_Management"

Add users to the security group

foreach ($user in $users) {
    $userEmail = $user | Select-Object -ExpandProperty userPrincipalName

Assuming the email address field is named ‘userPrincipalName’

Write-Host "User email: $userEmail"    

Print the extracted email address
Add-DistributionGroupMember -Identity $mailEnabledSecurityGroup -Member $userEmail
}

Output error from PowerShell.

Add-DistributionGroupMember : Cannot validate argument on parameter 'Member'. The argument is null. Provide a valid
value for the argument, and then try running the command again.
At line:14 char:77
+ ... ionGroupMember -Identity $mailEnabledSecurityGroup -Member $userEmail
+                                                                ~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Add-DistributionGroupMember], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Add-DistributionGroupMember