troubleshooting Question

How do i query users that have not logged into their mailbox in the last 6 months using Powershell or powerGUI

Avatar of JPVG
JPVGFlag for Afghanistan asked on
Microsoft Legacy OSExchangePowershell
11 Comments1 Solution851 ViewsLast Modified:
I almost got what i need via the command below but the user email address is missing and the output needs to be in .CSV format and not .txt as we need to work with the output. Also, the mail size would be nice in KB and descending in size. :) I've tried tweaking the command but i get errors.

get-mailbox -IgnoreDefaultScope -ResultSize Unlimited | Get-MailboxStatistics | where {$_.lastlogontime -le ((Get-Date).Adddays(-180))} | Format-Table DisplayName, @{expression = {$_.TotalItemSize.Value.ToMB();label="TotalItemSizeKB"}} | ft displayname,lastlogontime,totalitemsize -AutoSize > c:\Last_6_Months.txt

I also tried PowerGUI which gave me everything i needed except filtering out the users that have not logged in in 180 days. Either the Shell or PowerGUI would work for me. :)

$MailboxData = @()

$mailboxes = Get-Mailbox -ResultSize unlimited
foreach ($mailbox in $mailboxes) {

$DBObject = new-object PSObject
$DBObject | add-member NoteProperty -Name Alias -Value $Mailbox.alias

$DBObject | add-member NoteProperty -Name OU -Value $Mailbox.organizationalunit
$DBObject | add-member NoteProperty -Name EmailAddress -Value $Mailbox.primarysmtpaddress

$DBObject | add-member NoteProperty -Name Items -Value (Get-MailboxStatistics $mailbox.alias).itemcount
$DBObject | add-member NoteProperty -Name StorageLimit -Value (Get-MailboxStatistics $mailbox.alias).storagelimitstatus

$DBObject | add-member NoteProperty -Name Size -Value (Get-MailboxStatistics $mailbox.alias).totalitemsize
$DBObject | add-member NoteProperty -Name ServerStore -Value (Get-MailboxStatistics $mailbox.alias).database

$DBObject | add-member NoteProperty -Name Database -Value (Get-MailboxStatistics $mailbox.alias).databasename
$MailboxData += $DBObject


$MailboxData | Export-Csv c:\mailboxreport.csv

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros