o365 users last login reports

Modified on Tue, 30 Jun at 3:29 PM


$Result=@() 

$mailboxes = Get-Mailbox -ResultSize Unlimited

$totalmbx = $mailboxes.Count

$i = 1 

$mailboxes | ForEach-Object {

$i++

$mbx = $_

$mbs = Get-MailboxStatistics -Identity $mbx.UserPrincipalName | Select LastLogonTime

if ($mbs.LastLogonTime -eq $null){

$lt = "Never Logged In"

}else{

$lt = $mbs.LastLogonTime }

 

Write-Progress -activity "Processing $mbx" -status "$i out of $totalmbx completed"

 

$Result += New-Object PSObject -property @{ 

Name = $mbx.DisplayName

UserPrincipalName = $mbx.UserPrincipalName

LastLogonTime = $lt }

}

 

$Result | Export-CSV "C:\O365-LastLogon-Info.csv" -NoTypeInformation -Encoding UTF8

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article