2

How do I filter out only the SMTP address? I want to report only on users with domain name @mydomain.com. All other domain names would be excluded. I'm attempting to run a report that would exclude certain SIP/SMTP addresses based off of the user's domain.

$CheckUser = Get-CsUser -Filter {SipAddress -eq $SIP}
  $s = 0
  While ($CheckUser -eq $null) {
    $CheckUser = Get-CsUser -Filter {SipAddress -eq $SIP}
    $s++
    If ($s -eq 2000) {
      $Date = Get-Date –f "MM/dd/yyyy HH:mm:ss"
      "[$Date] User $EUID did not complete OCS configuration"
      $ProcessedDateandTime = Get-Date
      $ProcessedDate = $ProcessedDateandTime.ToShortDateString()
      $ProcessedTime = $ProcessedDateandTime.ToShortTimeString()
      $ErrorCode = "12"
      Add-Content $ProcessedFileName "$ProcessedDate,$ProcessedTime,$EUID,Mailbox Created but OCS Timed Out.,$ErrorCode"
      Add-Content $ErrorLog "$ProcessedDate,$ProcessedTime,$EUID,Mailbox Created but OCS Timed Out."
      $FailureCount++
      Break
    }
  }
jscott
  • 24,484
  • 8
  • 79
  • 100
Aaron Harris
  • 21
  • 1
  • 3

2 Answers2

2

What I have understood from your question is that you want to list all mailboxes who have an smtp address ending in @mydomain.com ? Like a report, with all existing @mydomain.com email addresses ?

GET-MAILBOX * | where { $_.PrimarySMTPAddress.Domain -eq 'mydomain.com' }

Source : http://www.energizedtech.com/2010/01/powershell-exchange-2007-list.html

Hope that helps

Mutahir
  • 2,357
  • 2
  • 32
  • 42
0

I'm not quite sure where in your above script you would post this, but you can use the [string].EndsWith operator. E.g:

dir|?{$_.name.EndsWith("f")}

will show you every item in the current directory that ends in the letter f. So you might adjust this to:

|?{$_.emailaddress.EndsWith("example.org")}

after you're doing your Get- query

? is shorthand for Where-Object (the standard filtering object for a PS pipeline).

Mark Henderson
  • 68,823
  • 31
  • 180
  • 259