Link to home
Start Free TrialLog in
Avatar of K B
K BFlag for United States of America

asked on

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.
Avatar of becraig
becraig
Flag of United States of America image

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.
Avatar of K B

ASKER

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.
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.
Avatar of K B

ASKER

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.
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.
Avatar of K B

ASKER

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!
ASKER CERTIFIED SOLUTION
Avatar of Vasil Michev (MVP)
Vasil Michev (MVP)
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial