What happens when you are asked  to get an automate report from O365 with specific fields ASAP?

You task the system with a script like this

# Last Logon Time
# version 1.5
# Author: Hannel Hazeley | hhazeley@outlook.com

$timecode = get-date -format 'yyyyMMddHHmmss'

$MBXs = Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited

Foreach ($MBX in $MBXs)
Get-Mailbox $MBX.Identity | Select UserPrincipalName, DisplayName, @{Name="FisrtName";Expression={(Get-msoluser -UserPrincipalName $_.UserPrincipalName).FirstName}}, @{Name="LastName";Expression={(Get-msoluser -UserPrincipalName $_.UserPrincipalName).LastName}}, @{Name="LastLogonDate";Expression={(Get-MailboxStatistics $_.Identity).LastLogonTime}} | Export-Csv "$timecode`_LastLogonTime.csv" -NoTypeInformation -Append


This will give you a CSV file containing UserPrincipalName, DisplayName, FirstName, LastName and LastLogOnTime for all user mailboxes. Run at your own risk. 🙂

20150710 - LLT


Happy Friday…. Enjoy!