Now Back to the task, this was a mess whatever those two scripts you had did not take into account that this are not computers, this are users so the LastLogonDate is not a User Attribute and so forth. See below my script
#Import AD and Exchange Module (The Server Must have AD PowerShell Exchange PowerSHell Modules)
Import-Module ActiveDirectory
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
#OU Iformation (if needed) ( I am not using it on my example)
$OU="dc=domain,dc=com"
#Get Today's Date
$today = Get-Date
#Date Format for File Name
$date = Get-Date -Format "MMddyyyy"
#Define a work folder for the report
$WorkFolder="C:\Scripts"
#Define the number of days to search for users that have not logged in
$Days=$today.AddDays(-90)
#Search for users
Get-ADUser -Filter {LastLogonDate -lt $Days -And Enabled -eq $TRUE }} | Select SAMAccountname | ConvertTo-Csv -NoTypeInformation | % { $_ -replace '"', ""} | out-file "$WorkFolder\$date-Users.csv" -fo -en ascii
#Get all the Users from AD
$users= @(Get-Content $WorkFolder\$date-Users.csv)
#Loop for all the users to Report of All Mailboxes That are Inactive
foreach ($user in $users) {
Get-Mailbox -Identity $user | Select DisplayName,Database,WindowsEmailAddress,@{n="Size(MB)";e={[int]$(Get-MailboxStatistics $_.Alias).TotalItemSize.Value.ToMB()}} | Sort-Object "Size(MB)" -Descending | Export-Csv -Path $WorkFolder\MailboxStatistics-$date.csv -NoTypeInformation -Append
}
This will only give you the Reports of the Users That are Enabled and Have not logged in in the last 90 days. Now, give it a try and check it. If that is not what you are looking for then something else can be reviewed.