Project Work Hours
Sat & Sun 6am - 9am
Subscribe via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

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 |

$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!