Hello Guys,
Can someone please take a look at the script that i'm using to bulk remove secondary smtp address for all the mailboxes in a DistributionGroup.
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 infoscites.com
$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
The error that i'm getting is:
Cannot process argument transformation on parameter 'Identity'. Cannot convert the "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