Apr 24 2021 10:08 PM
Hi,
I'm trying to export csv file, with users that not logged on more then 90 days.
I tried to run this script:
Get-Mailbox -RecipientType 'UserMailbox' | Get-MailboxStatistics | Sort-Object LastLogonTime | Where {$_.LastLogonTime –lt ([System.DateTime]::Now).AddDays(-90) } | Export-Csv "D:\Logs\O365MAILBOXSTATS_REPORT.CSV" -NoTypeInformation
I didn't received any csv file after the script finish.
Also, I got this errors :
Get-MailboxStatistics: The specified mailbox "User name" isn't unique.
My goal is to get users that not connected to O365 more then 90 days.
Apr 26 2021 01:15 AM
Hello @dannytveria,
Your error means that PowerShell is trying to use not unique value for -Identity parameter of Get-MailboxStatistics cmdlet.
For Identity parameter you can use any value that uniquely identifies the mailbox. For example:
In your case one of the options would be to use UPN as it is unique within your organization.
You need to modify your script to explicitly pass UserPrincipalName to Get-MailboxStatistics.
Hope that helps.
Apr 26 2021 01:35 AM
Hi Andy,
thanks for your response.
I didn`t understand where exactly I need to change value.
can you please help me with my example?
Apr 26 2021 03:25 AM
Hello @dannytveria,
Try this:
Get-Mailbox -RecipientType 'UserMailbox' |%{ Get-MailboxStatistics $_.UserPrincipalName | Sort-Object LastLogonTime | Where {$_.LastLogonTime -lt ([System.DateTime]::Now).AddDays(-90) } | Export-Csv "D:\Logs\O365MAILBOXSTATS_REPORT.CSV" -NoTypeInformation -Append}
Hope that helps.
Apr 26 2021 04:01 AM
Apr 26 2021 04:14 AM
Hello @dannytveria,
Add -ResultSize Unlimited to Get-Mailbox:
Get-Mailbox -RecipientType 'UserMailbox' -ResultSize Unlimited | ...
Also try to remove filter with LastLogonDate just to test of that it works.
It might be that there are no users who accessed their mailbox more that 90 days ago.
Hope that helps.
Apr 26 2021 05:28 AM - edited Apr 26 2021 06:10 AM
It`s worked with the LastLogonDate.
the LastLogonDate field is when the user last login to his mailbox on 365?
Or which field actually shows the last use mailbox?
Apr 26 2021 06:32 AM
The research was done on many real-time users, and we have concluded that getting Office 365 user’s inactive time from LastUserActionTime is the best.
Reference: https://o365reports.com/2019/06/18/office-365-users-last-logon-time-incorrect/
Hope that helps.
Apr 27 2021 01:25 AM