In your Exchange Environment, you might have users who have not\are not logging onto their mailboxes from N number of days.

What if you are asked to find all of those or the ones specific to a Server\DB.

There can be multiple reasons why you might have to find such users, one of which was to find how many mailboxes aren't being used for past 30 days.

Here is a script to help you with the same:
$ExServer = Read-host "`n Enter ServerName";[Datetime]$mydate = (Get-Date).AddDays(-30).Date; $CorrectDate = $mydate -f "G";
Get-mailbox -server $ExServer -resultsize unlimited | Get-MailboxStatistics | ?{($_.LastLogonTime -lt "$CorrectDate") -and ($_.LastLogonTime -ne $null)} 
  • "$ExServer" is used twice and is the variable which holds ServerName,  you can replace it with "$DB" to find users according to a Database
  • "$mydate = (Get-Date).AddDays(-30).Date" is the variable holding days passed, you can edit the number according to your needs
  • You can also use below to find all users who haven't logged on to their mailboxes from past 30 days.
[Datetime]$mydate = (Get-Date).AddDays(-30).Date; $CorrectDate = $mydate -f "G";
Get-mailbox -resultsize unlimited | Get-MailboxStatistics | ?{($_.LastLogonTime -lt "$CorrectDate") -and ($_.LastLogonTime -ne $null)}