appending text to automate domain name change and alias

Hi, I’m want make bulk changes using below script to change primary domain (the new domain) and make alias for old domain. My csv has usernname, proxyaddress, proxyaddress2:

$users = import-csv "c:\import.csv"

ForEach ( $user in $users)
{
#define domain here
$domain="@jhuccp.ng"

#adding proxies
$SMTP1="SMTP:"
$SMTP2="smtp:"

#adding all
$SMTP1=$SMTP1 + $users.proxyaddress + $domain
$SMTP2=$SMTP2 + $users.proxyaddress2 + $domain
$email=$user.proxyaddress + $domain
$upn=$email

set-azureAduser $users.Username -add @{ProxyAddresses=$SMTP1}
set-azureAduser $users.Username -add @{ProxyAddresses=$SMTP2}

set-azureAduser $users.Username -emailaddress $email
set-azureAduser $users.Username -userprincipalname $upn
}

there is error at below:

Set-AzureADUser : A positional parameter cannot be found that accepts argument 'System.Object[]'.
At line:18 char:1
+ set-azureAduser $users.Username -add @{ProxyAddresses=$SMTP1}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-AzureADUser], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Open.AzureAD16.PowerShell.SetUser

Please assist. thanks

Hello kounzo95,
Welcome to PowerShell.org forum.
Please read Read Me Before Posting! You’ll be Glad You Did! and make sure to format your code property going forward.

From the script it looks like you are operating with the collection of usernames ($users.proxyaddres ) not specific username that you have inside your foreach loop ($user).

Try changing $users.proxyaddress to $user.

Also I would move the domain definition outside of Foreach loop. Right now you are initializing $domain variable for each user.

Hope that helps.