Solved

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

Posted on 2013-11-26
5
626 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
THank you so much!!!! You are great!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
In this video we show how to create an email address policy in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Mail Flow…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now