# Bulk remove secondary SMTP error

**URL:** <https://forums.powershell.org/t/bulk-remove-secondary-smtp-error/16483>\
**Category:** PowerShell Help\
**Created:** [May 11, 2021, 6:01am UTC](https://forums.powershell.org/t/bulk-remove-secondary-smtp-error/16483 "2021-05-11T06:01:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![3af1](https://avatars.discourse-cdn.com/v4/letter/3/e5b9ba/32.png) [@3af1](https://forums.powershell.org/u/3af1)\
**Post date:** [May 11, 2021, 6:01am UTC](https://forums.powershell.org/t/bulk-remove-secondary-smtp-error/16483/1 "2021-05-11T06:01:29Z")

</div>

I’m a noob at PowerShell and as such I apologize if it’s too simple for to not get. so, I have a script online, I believe it’s by Ali Tajran. Can somehow be kind enough to take a look at script and the error and let guide me?

script:  
Start-transcript -path C:\Users\user1\Desktop\Dry-Run\remove-smpt-address-5.log -append

# Get all mailboxes

$Mailboxes = Get-DistributionGroupMember -Identity “Marketing” -ResultSize unlimited

# Loop through each mailbox

foreach ($Mailbox.name in $Mailboxes) {

```
# Add the domain to remove
$Mailbox.EmailAddresses | Where-Object { $_.AddressString -like "*@xyz.com" } | ForEach-Object {

    # Remove the -WhatIf parameter after you tested and are sure to remove the secondary email addresses
    Set-Mailbox $Mailbox -EmailAddresses @{remove = $_ } -WhatIf

    # Write output
    Write-Host "Removing $_ from $Mailbox Mailbox" -ForegroundColor Green
}

```

}

Stop-Transcript

Error:

Cannot process argument transformation on parameter ‘Identity’. Cannot convert the “[domain.com/Users/Doe](http://domain.com/Users/Doe), Jame” value of type “Microsoft.Exchange.Data.Directory.Management.ReducedRecipient” to type  
“Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter”.  
+ CategoryInfo : InvalidData: (🙂 [Set-Mailbox], ParameterBindin…mationException  
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Mailbox  
+ PSComputerName : [exchangeserver.domain.com](http://exchangeserver.domain.com)

Thanks,

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [May 11, 2021, 6:28pm UTC](https://forums.powershell.org/t/bulk-remove-secondary-smtp-error/16483/2 "2021-05-11T18:28:01Z")

</div>

email address should be in the format `Jwoods@contoso.com` I think. Print and debug without wrapping `$_` in quotes, just like `Write-Output $_` before `Set-Mailbox` and see how is the format.

---

<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:26pm UTC](https://forums.powershell.org/t/bulk-remove-secondary-smtp-error/16483/3 "2024-05-16T20:26:26Z")

</div>


