Link to home
Start Free TrialLog in
Avatar of Wdntulk2no-
Wdntulk2no-Flag for United States of America

asked on

Looking to remove SMTP address via command shell

OK here is the deal, i am looking for a SIMPLE command one line to just remove an smtp nothing fancy:
Simply put i want to pick 1 account JDoe and remove an alias that is not his primary with a command line
Avatar of Sirreal45
Sirreal45
Flag of United States of America image

Are you looking to remove the alias or an SMTP address?

Using the Exchange Shell?

set-mailbox "username" -Alias <value>

for the SMTP address, it would depend on what you currently have listed and if you are using x400 addresses still or not. If there are multiple addresses that you want to keep, you'll have to list each one here seperated by commas.

set-mailbox "username" -EmailAddresses {SMTP:email@address}

I don't believe you can do any of this from just the standard command line without calling a script.
Here you go
Get-Mailbox | foreach {
for ($i=$_.EmailAddresses.Count;$i -ge 0; $i--)
{
$address = $_.EmailAddresses[$i]
if ($address.SmtpAddress -like "*@target.local" )
{
Write-host("Remove smtp adress: " + $address.AddressString.ToString() )
$_.EmailAddresses.RemoveAt($i)
}
}
$_|set-mailbox
}
ASKER CERTIFIED SOLUTION
Avatar of Ajit663
Ajit663
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Wdntulk2no-

ASKER

Unable to verify this solution. I no longer have access to this server so i cannot be fore sure if it would work or not.