Solved

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

Posted on 2013-11-26
5
642 Views
Last Modified: 2013-12-06
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
Comment
Question by:claudiamcse
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:Enphyniti
ID: 39678882
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
 

Author Comment

by:claudiamcse
ID: 39678958
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
 
LVL 16

Expert Comment

by:Enphyniti
ID: 39679237
Remove the ! And the parens from the search statement in the previous one.  On mobile now, otherwise I can post an example later
0
 
LVL 16

Accepted Solution

by:
Enphyniti earned 500 total points
ID: 39679306
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
 

Author Closing Comment

by:claudiamcse
ID: 39701751
THank you so much!!!! You are great!
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or imporā€¦
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlleā€¦
how to add IIS SMTP to handle application/Scanner relays into office 365.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question