# appending text to automate domain name change and alias

**URL:** <https://forums.powershell.org/t/appending-text-to-automate-domain-name-change-and-alias/14653>\
**Category:** PowerShell Help\
**Created:** [July 12, 2020, 7:09am UTC](https://forums.powershell.org/t/appending-text-to-automate-domain-name-change-and-alias/14653 "2020-07-12T07:09:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kounzo](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@kounzo](https://forums.powershell.org/u/kounzo)\
**Post date:** [July 12, 2020, 7:09am UTC](https://forums.powershell.org/t/appending-text-to-automate-domain-name-change-and-alias/14653/1 "2020-07-12T07:09:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andysvints](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/andysvints/32/1017_2.png) [@andysvints](https://forums.powershell.org/u/andysvints)\
**Post date:** [July 12, 2020, 6:41pm UTC](https://forums.powershell.org/t/appending-text-to-automate-domain-name-change-and-alias/14653/2 "2020-07-12T18:41:33Z")

</div>

Hello kounzo95,  
Welcome to [PowerShell.org](http://PowerShell.org) forum.  
Please read [Read Me Before Posting! You’ll be Glad You Did!](https://powershell.org/forums/topic/read-me-before-posting-youll-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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/appending-text-to-automate-domain-name-change-and-alias/14653/3 "2024-05-16T20:29:14Z")

</div>


