Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

powershell match get mailbox

Posted on 2015-02-11
8
Medium Priority
?
208 Views
Last Modified: 2015-02-20
I have been tasked with trying to locate all the alias and verify that the smtp address matches with each account. The issue is I am doing this by hand and with many accounts it will take a while.
what powershell command will allow me to match the aliasname with the primarysmtpaddress

I am stuck and cannot get beyond this point.

get-mailbox -resultsize:unlimited
0
Comment
Question by:techdrive
[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
  • 4
  • 3
8 Comments
 
LVL 17

Expert Comment

by:lruiz52
ID: 40603820
Try something like;

Get-Mailbox -resultsize unlimited | Select Name, Alias, PrimarySMTPAddress, @{Name='EmailAddresses';Expression={[string]::join(";", ($_.EmailAddresses -match 'SMTP'))}} | Export-CSV c:\EmailAddress.csv
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40603828
Use the below command below...

On Screen
$Users = get-content "c:\users.txt"
Foreach ($User in $Users) {
Get-Mailbox -Identity $User | select DisplayName, PrimarySMTPAddress
}

Open in new window


To CSV FIle
$Users = get-content "c:\users.txt"
Foreach ($User in $Users) {
Get-Mailbox -Identity $User | select DisplayName, PrimarySMTPAddress | out-file "c:\userSMTPAddresses.csv" -append
}

Open in new window

0
 

Author Comment

by:techdrive
ID: 40603841
thanks will but may I also add. Looking for something that would automate this instead of eye balling. I guess I would have to remove the domain @company.com because the alias is suppose to match the primarysmtpaddress and if it does not I would like a report.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40603851
You can use any of the following methods to look up a mailbox using the Identity parameter.

-Identity <MailboxIdParameter>
    The Identity parameter identifies the mailbox. You can use one of the following values:
    * GUID
    * Distinguished name (DN)
    * Domain\Account
    * User principal name (UPN)
    * LegacyExchangeDN
    * SmtpAddress
    * Alias

    Required?                    false
    Position?                    1
    Default value
    Accept pipeline input?       True
    Accept wildcard characters?  true

Will.
0
 

Author Comment

by:techdrive
ID: 40603953
Let me clarify I might not be coming across clearly.Iruiz52 is somewhat close to what I am asking.

This below is a good idea but will not work

Get-mailbox | select name, ($_.alias -match $_.primarysmtpaddress)

1) I wanted something that while its processing this would at least when doing the comparison would filter out the domain name@company.com and then that way would be able to compare the alias in which we have firstname.lastname to the primarysmtpaddress firstname.lastname@company.com which would by powershell do the comparison for me.


So here is my data in theory in exchange and how it sees this.

               alias                                                                                primarysmtpaddress
     firstname.lastname                                                          firstname.lastname@somecompany.com
     dollar.bill                                                                           dollar.bill@somecompany.com
     jane.doe                                                                             jane.doe@somecompany.com


Step 1 would like for the somecompany.com to be removed so that it can filter it properly. NOT in the exchange environment but some substring for processing.


             alias                                                                                primarysmtpaddress
     firstname.lastname                                                          firstname.lastname
     dollar.bill                                                                           dollar.bill
     jane.doe                                                                             jane.doe

Now its the same now and powershell can compare the alias vs the primarysmtpaddress and anything that does not matches comes back and reports.
0
 
LVL 53

Accepted Solution

by:
Will Szymkowski earned 2000 total points
ID: 40604665
Personally this matching would be much quicker in excel. When you have your values in Excel for Alias and SMTPAddress just highlight the SMTPAddress column select Find/Replace. Then Find @domain.com, replace leave "blank" (this will remove the @domain.com from the SMTPAddress.

From there all you need to do is click the Data Tab and select "remove duplicates" it will remove all of the entries that are the same and leave you with the ones that are not.

Not exactly what you were looking for in a script format but another way of doing this.

Use the script below to export Alias and PrimarySMTPAddress.
get-mailbox -resultsize "unlimited" | select Alias, PrimarySMTPAddress | Export-csv "c:\compairusers.csv" -nti

Open in new window


Will.
0
 

Author Comment

by:techdrive
ID: 40604835
thanks i was actually thinking of settling for excel. It seems to be the best way to do this.
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40604843
Yeah why over complicate things if you are already exporting it to a csv.

Will.
0

Featured Post

Looking for the Wi-Fi vendor that's right for you?

We know how difficult it can be to evaluate Wi-Fi vendors, so we created this helpful Wi-Fi Buyer's Guide to help you find the Wi-Fi vendor that's right for your business! Download the guide and get started on our checklist today!

Question has a verified solution.

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

How to deal with a specific error when using the Enable-RemoteMailbox cmdlet to create a mailbox in the cloud-based service, for an existing user in an on-premises Active Directory.
I don't pretend to be an expert at this, but I have found a few things that are useful. I hope that sharing them here will help others, so they will not have to face some rather hard choices. Since I felt this to be a topic of enough importance and…
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

650 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