Author Posts

December 12, 2016 at 7:01 pm

Hi, we have a hybrid Exchange setup and we're trying to find all mailboxes that don't have 2 smtp email addresses / proxy addresses. I can check it on either the Exchange server or a DC, whichever would be easier, but below is what I've been trying.

Get-Mailbox -OrganizationalUnit "TEST OU" | ?{$_.EmailAddresses -like "*domain.mail.onmicrosoft.com*"}

This works fine in listing the mailboxes that have it assigned, but I need to find the ones that don't. It's a Monday and I can't think of how to do the reverse, would I have to use a "If..Then" statement or something?

Also, there should be two smtp addresses, domain.onmicrosoft.com and domain.mail.onmicrosoft.com, so I need to search and make sure both are there.

December 12, 2016 at 7:05 pm

Use -notlike instead of -like?

December 12, 2016 at 7:12 pm

Tried that, it still lists everyone in the OU. Tried it with an * and without, same thing.

December 12, 2016 at 7:17 pm

Are the "wrong" people in possession of a blank address? And I'm thinking that the field is actually a collection capable of holding multiple values – which means -notlike wouldn't work. You'd need a -notcontains or something, but those don't do wildcards. You might end up just enumerating every user and running through a ForEach to examine each one. I'm not sure AD is going to be able to filter this server-side for you.

December 12, 2016 at 7:24 pm

Yeah the EmailAddresses property from Get-Mailbox can contain multiple addresses (X500, smtp, etc.) and each user should have a few already because of an email address policy. I tried it with -notcontains as well, still no luck 🙁

December 12, 2016 at 7:26 pm

Is there one mailbox that you know you can test against? If like works notlike should also work. I don't have any that are missing.

get-mailbox -Filter {emailaddresses -notlike "*microsoft.com"}

get-mailbox -Filter {emailaddresses -like "*microsoft.com"} | select name,alias,servername,@{n='emailaddys';e={($_.emailaddresses | ?{$_ -match 'microsoft'})-join '; '}}

December 12, 2016 at 7:44 pm

Just the one line:

get-mailbox -Filter {emailaddresses -notlike "*microsoft.com"}

is working, thanks!!!

December 12, 2016 at 8:02 pm

Wonder why the -notlike filter works before the pipe, but not after? Weird.

December 12, 2016 at 8:12 pm

This is a bit too complicated for a one liner. Emailaddresses is a collection of objects. It would probably be easier to write a function to test them.

function checksmtp {
  param($adr)
  
  $found1 = $false
  $found2 = $false
  foreach ($a in $adr) {
    if ($a.prefixstring -eq 'smtp') {
      if ($a.addressstring -like "*dom1.com") {
        $found1 = $true
      }
      if ($a.addressstring -like "*dom2.com") {
        $found2	= $true
      }
    }
  }
  ($found1 -and $found2)
}

Get-Mailbox -OrganizationalUnit "TEST OU" | ? {-not (checksmtp($_.emailaddresses))}

December 12, 2016 at 8:32 pm

It is a multi-valued property.

get-mailbox | ?{($_.emailaddresses -join ';') -notmatch 'microsoft'}
get-mailbox | ?{($_.emailaddresses -join ';') -match 'microsoft'}