Solved

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

Posted on 2013-11-26
5
660 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
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 …
This video discusses moving either the default database or any database to a new volume.

687 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