Forum Discussion
dannytveria
Apr 25, 2021Copper Contributor
Export last log on more 90 days Office 365
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 La...
AndySvints
Apr 26, 2021Steel Contributor
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:
- Name
- Alias
- Distinguished name (DN)
- Canonical DN
- Domain\Username
- Email address
- GUID
- LegacyExchangeDN
- SamAccountName
- User ID or user principal name (UPN)
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.
dannytveria
Apr 26, 2021Copper Contributor
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?
- AndySvintsApr 26, 2021Steel Contributor
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.
- dannytveriaApr 26, 2021Copper ContributorHi Andy,
thanks for the help.
I getting a warning:
By default, only the first 1000 items are returned. Use the ResultSize parameter to specify the number of items returned.
Also, no CSV file not created maybe because of the warning?- AndySvintsApr 26, 2021Steel Contributor
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.