Solved

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

Posted on 2013-11-26
5
650 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
This article outlines the process to identify and resolve account lockout in an Active Directory environment.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

680 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