none
Get-mailbox where e-mail does not containt spesific domain

    Question

  • Hi all,

    Wondering if anyone could help me with the following:

    Would like to get all mailboxes that does not have *@domain.com as e-mail (default or alias) and export it to csv file.

    Get-Mailbox -ResultSize Unlimited | Where-Object {($_.SMTPAddress -notcontains "*@domain.com*")} |export-csv C:\Scripts\mailboxes.csv

    Tried the above but did not work.

    Thanks!


    Please mark as helpful if you find my contribution useful or as an answer if it does answer your question. That will encourage me - and others - to take time out to help you. Thank you! Off2work


    • Edited by Off2work Friday, August 29, 2014 3:44 PM edit
    Friday, August 29, 2014 3:26 PM

Answers

  • I would look at doing the filtering on the server side to speed things up:

    Example:

    get-mailbox -resultsize unlimited  -Filter { emailaddresses -notlike "*@domain.com"} | export-csv C:\Scripts\mailboxes.csv


    Twitter!: Please Note: My Posts are provided “AS IS” without warranty of any kind, either expressed or implied.

    Friday, August 29, 2014 7:03 PM
    Moderator

All replies

  • You can filter from MMC and export to CSV, TXT, etc. Screen below

    This is in Exchange2010 but similar in Exchange2013 


    Thanks, MAS
    Please mark as helpful if you find my comment helpful or as an answer if it does answer your question. That will encourage me - and others - to take time out to help you.

    Friday, August 29, 2014 4:52 PM
  • Hi Mas,

    thanks for reply,ecp 2013 doesnt have option like 2010.So would prefer this in Exchange powershell command.

    Maybe i can add some filters here i dont know about?

    thanks!


    Please mark as helpful if you find my contribution useful or as an answer if it does answer your question. That will encourage me - and others - to take time out to help you. Thank you! Off2work

    Friday, August 29, 2014 5:19 PM
  • You could try this from EMS

    Get-Mailbox -resultsize unlimited | Select-Object displayname -expandproperty emailaddresses| Where-Object {$_.smtpaddress -notlike "*domaintoexclude.com"}| Select-Object displayName,SmtpAddress | Export-csv C:\Users.csv


    Thanks, MAS
    Please mark as helpful if you find my comment helpful or as an answer if it does answer your question. That will encourage me - and others - to take time out to help you.

    Friday, August 29, 2014 6:32 PM
  • I would look at doing the filtering on the server side to speed things up:

    Example:

    get-mailbox -resultsize unlimited  -Filter { emailaddresses -notlike "*@domain.com"} | export-csv C:\Scripts\mailboxes.csv


    Twitter!: Please Note: My Posts are provided “AS IS” without warranty of any kind, either expressed or implied.

    Friday, August 29, 2014 7:03 PM
    Moderator
  • Sry for late reply,but thanks Andy Your command work :)


    Please mark as helpful if you find my contribution useful or as an answer if it does answer your question. That will encourage me - and others - to take time out to help you. Thank you! Off2work

    Friday, September 05, 2014 1:45 PM