[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 703
  • Last Modified:

Help with the script. Need the line that lists if users have this particular email address.

Hello,
I need a script that checks all the users and lists the users that are missing this email address domain.mail.onmicrosoft.com

So, I used the script below to disable the email policy and add this email address domain.mail.onmicrosoft.com and now I need to get the list of users who dont have it.

Note: all users have a least three addresses so I dont want to go through each of them. I just need to know the results for that one address above

$users= get-mailbox
$Users | %{set-mailbox $_.Identity -EmailAddressPolicyEnabled $false}  
Wait 10 min
$Users | %{get-mailbox $_.Identity | Select Displayname,EmailaddresspolicyEnabled}
foreach ($a in $users) {$a.emailaddresses.Add("smtp:$($a.alias)@domain.mail.onmicrosoft.com")}  
$users | %{Set-Mailbox $_.Identity -EmailAddresses $_.EmailAddresses}
get-mailbox  | Select Displayname,EmailaddresspolicyEnabled
0
claudiamcse
Asked:
claudiamcse
  • 3
  • 2
1 Solution
 
Jon BrelieSystem ArchitectCommented:
Get-Mailbox -resultsize Unlimited | ? { !($_.emailaddresses -like "*domain.mail.onmicrosoft.com*") }

This will list all mailboxes that do not have "domain.mail.onmicrosoft.com" listed in their EmailAddresses property.
0
 
claudiamcseAuthor Commented:
Awesome!! THank you so much!! Can you please also give me a script that lists all users that have domain.mail.onmicrosoft.com email address?
0
 
Jon BrelieSystem ArchitectCommented:
Remove the ! And the parens from the search statement in the previous one.  On mobile now, otherwise I can post an example later
0
 
Jon BrelieSystem ArchitectCommented:
Get-Mailbox -resultsize Unlimited | ? { $_.emailaddresses -like "*domain.mail.onmicrosoft.com*" }

This will do it, but it will match ANY address with the domain specified.  Not necessarily the one you specified using the $mailbox.alias@domain.

To do that you'd need a slightly more complicated query that uses a foreach loop on each mailbox returned to capture $_.alias and do a specific match in much the same way you added the address in the first place.

Specifically: "*$($_.alias)@domain.mail.onmicrosoft.com*"

Make sense?
0
 
claudiamcseAuthor Commented:
THank you so much!!!! You are great!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now