# Set-Mailbox proxy addresses

**URL:** <https://forums.powershell.org/t/set-mailbox-proxy-addresses/4395>\
**Category:** PowerShell Help\
**Created:** [June 18, 2015, 11:16pm UTC](https://forums.powershell.org/t/set-mailbox-proxy-addresses/4395 "2015-06-18T23:16:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lemonade](https://avatars.discourse-cdn.com/v4/letter/l/ac8455/32.png) [@lemonade](https://forums.powershell.org/u/lemonade)\
**Post date:** [June 18, 2015, 11:16pm UTC](https://forums.powershell.org/t/set-mailbox-proxy-addresses/4395/1 "2015-06-18T23:16:33Z")

</div>

I’m trying to add several proxy addresses to all user accounts on the domain, I can do via exporting the proxy addresses and then importing them. But was wondering if I can do without using csv’s.

But i get “System.Collections.Hashtable” errors

This wont work  
`
$users = Get-ADUser -SearchBase “ou=users,dc=contoso,dc=com” -Filter { (Enabled -eq $true) -and (mail -like “*”) } -Properties displayName
foreach($user in $users){
$name = ($user.DisplayName -split " ")
$firstName = $name[0]
$surname = $name[1]
$addresses = $firstName + “.” + $surname + ‘@email1.com’ + “,” + `
$firstName + “.” + $surname + ‘@email2.com’ + “,” + `
$firstName + “.” + $surname + ‘@email3.com’ + “,” + `
$firstName + “.” + $surname + ‘@email4.com’ + “,” + `
$firstName + “.” + $surname + ‘@email5.com’
Set-Mailbox -Identity $name -EmailAddresses @{add= $addresses}
}
`

This does work  
`
$users = Get-ADUser -SearchBase “ou=users,dc=contoso,dc=com” -Filter { (Enabled -eq $true) -and (mail -like “*”) } -Properties displayName
foreach($user in $users){
$displayname = $user.DisplayName
$name = ($user.DisplayName -split " ")
$firstName = $name[0]
$surname = $name[1]
$addresses = $firstName + “.” + $surname + ‘@email1.com’ + “,” + `
$firstName + “.” + $surname + ‘@email2.com’ + “,” + `
$firstName + “.” + $surname + ‘@email3.com’ + “,” + `
$firstName + “.” + $surname + ‘@email4.com’ + “,” + `
$firstName + “.” + $surname + ‘@email5.com’
New-Object -TypeName PSCustomObject -Property @{
Name = $displayname
ProxyAddresses = $addresses
} | Export-Csv -Path c:\temp$displayname.csv
Import-Csv c:\temp$displayname.csv | ForEach-Object{
$name = $.Name
$proxy = $.ProxyAddresses -split ‘,’
Set-Mailbox -Identity $name -EmailAddresses @{add= $proxy}
}
}
`

Thanks

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [June 19, 2015, 12:14am UTC](https://forums.powershell.org/t/set-mailbox-proxy-addresses/4395/2 "2015-06-19T00:14:04Z")

</div>

As a note, all that string concatenation isn’t strictly necessary. PowerShell replaces variables with their values inside double quotes. Just makes reading the code a little easier.

The help says that -EmailAddresses accepts one object of the type ProxyAddressCollection. You’re providing a single, comma-delimited string as a single value within a hash table.

One way to do this:

$foo = get-mailbox bsuneja  
$foo.EmailAddresses += “bsuneja@e14labs.com”,”bharat.suneja@e14labs.com”  
$foo | set-mailbox

Notice the comma location in relation to the quotes: It’s OUTSIDE the quotes. So this example is appending two new values to the proper, and then passing the mailbox object to Set-Mailbox. That’s because it’s often easier to get the necessary collection object by just getting the mailbox.

But, if you prefer:

Set-Mailbox bsuneja -EmailAddresses @{Add=‘bharat.suneja@e14labs.com’}

This is closer to what you’re trying to do, except the hash table needs a key (either ‘Add’ or ‘Remove’), with the value being the e-mail address. I imagine this would also be legal:

Set-Mailbox bsuneja -EmailAddresses @{Add=‘bharat.suneja@e14labs.com’;Add=‘poo@lovable.com’}

I’ve given two key/value pairs, here.

Stolen from [http://exchangepedia.com/2007/03/how-to-add-additional-email-addresses-to-a-recipient.html](http://exchangepedia.com/2007/03/how-to-add-additional-email-addresses-to-a-recipient.html).

---

<div class="post-metadata">

**Author:** ![max-kozlov](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@max-kozlov](https://forums.powershell.org/u/max-kozlov)\
**Post date:** [June 21, 2015, 7:31pm UTC](https://forums.powershell.org/t/set-mailbox-proxy-addresses/4395/3 "2015-06-21T19:31:19Z")

</div>

Don, in this example you make an error:  
`Set-Mailbox bsuneja -EmailAddresses @{Add=‘bharat.suneja@e14labs.com’;Add=‘poo@lovable.com’}`  
This leads to double hash key, the right oneliner is  
`Set-Mailbox bsuneja -EmailAddresses @{Add=‘bharat.suneja@e14labs.com’,‘poo@lovable.com’}`

---

<div class="post-metadata">

**Author:** ![rdtechie](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rdtechie/32/273_2.png) [@rdtechie](https://forums.powershell.org/u/rdtechie)\
**Post date:** [June 22, 2015, 12:48am UTC](https://forums.powershell.org/t/set-mailbox-proxy-addresses/4395/4 "2015-06-22T00:48:36Z")

</div>

If you want to use variables in your MultiValuedProperty, this is a working syntax:

```
Set-Mailbox -Identity $user.SamAccountName -EmailAddresses @{'Add' = ($user.GivenName + '.' + $user.Surname + '@domain.com')}
```

---

<div class="post-metadata">

**Author:** ![lemonade](https://avatars.discourse-cdn.com/v4/letter/l/ac8455/32.png) [@lemonade](https://forums.powershell.org/u/lemonade)\
**Post date:** [July 8, 2015, 1:18am UTC](https://forums.powershell.org/t/set-mailbox-proxy-addresses/4395/5 "2015-07-08T01:18:37Z")

</div>

Cant seem to get it working, its the same with removing a single email address

Set-Mailbox $user.DisplayName -EmailAddresses @{‘remove’=($user.mail)}

Still getting a data validation exception

---

<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:45pm UTC](https://forums.powershell.org/t/set-mailbox-proxy-addresses/4395/6 "2024-05-16T20:45:03Z")

</div>

Closed on May 16, 2024, 8:45pm UTC


