Powershell to combine Get-RemoteMailbox and Get-MailboxStatistics

This is in a Hybrid / Office 365 environment
Any command that gets this job done is great.

I need the SamAccountName and LastLogontime in the same report for >200,000 Mailboxes.
The only way I can see to grab the SamAccountName is with the Get-RemoteMailbox command via the on-premise Exchange 2010 EMS.  

My question is:
How do I get SamAccountName and LastLogontime in the same report?

Thank you for your time in advance!
K.B.
LVL 8
K BAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

becraigCommented:
Are you checking for last login time on premises ?
Whatever the method, simply populate an array with the Sam account name then do the second lookup using a for each loop.

Then you can create a hash table with the results and pipe any values you need to export csv.
0
K BAuthor Commented:
All the information (Display Name, PrimarySmtpAddress, LastLogonTime) is in the cloud except for SamAccountName (which I can only find with Get-RemoteMailbox.)
I am relying on your expertise for the code as I am not a PowerShell expert - especially with arrays.
0
Vasil Michev (MVP)Commented:
You can load both the cloud cmdlets and the on-prem ones in the same shell. Running this for 200k mailboxes against EO will be a pain, you are probably better off using the built-in activity report from the portal or using 3rd party tools.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

K BAuthor Commented:
Vasil,

Thank you for your reply.  I will look at the built-in reports again.  I couldn't find much but perhaps I was not looking in the correct area.

I started to think that I might be able to pull two reports Get-RemoteMailbox and Get-MailboxStatistics - both with data needed and both with PrimarySmtpAddress attribute.  I could then allow Excel to do a match and join against the common data in the PrimarySmtpAddress column.  I haven't tried this yet but just throwing that out there.

I also am awaiting a machine on-premise where I can safely load AD/Exchange/Azure cmdlets.  Also, I can load Quest cmdlets there too.  I know the data will take a while to pull but I can break it down via smaller chunks to test I suppose.

Perhaps that will work as I do not think I will be able to purchase a third-party tool unless it is fairly inexpensive.

Thanks again!

K.B.
0
Vasil Michev (MVP)Commented:
You dont really need Excel, you can do something like this:

Get-MailboxStatistics vasil | select LastLogontime,@{n="SamAccountName";e={(Get-RemoteMailbox vasil).SamAccountName}}

Open in new window


The problem is that it will take you ages to get that info from EO with such amount of mailboxes, and the sessions will more than likely going to get disconnected.
0
K BAuthor Commented:
What would the syntax be if I wanted to try it one letter at a time? In other words 26 passes at the data. I need to get this data somehow and I couldn't find it in the canned reports.

Thanks for your reply again Vasil!
0
Vasil Michev (MVP)Commented:
It's probably best to export the list of mailboxes via the EMS on-prem, at least it will be faster. Then you can iterate over them and get the mailboxstatistics from EO. Something like this:

Get-RemoteMailbox -ResultSize Unlimited -Filter {Name -like "a*"} | select SamAccountName,@{n="LastLogontime";e={(Get-MailboxStatistics $_.Identity).LastLogontime}}

Open in new window


But replace with the relevant Get-MailboxStatistics cmdlet for the EO session.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.