We help IT Professionals succeed at work.

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

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
}
Comment
Watch Question

Author

Commented:
I actually tried this before but it didn't work for me. I don't have the paid version of Quest, i have just PowerGUI. If it should also work with PowerGUI, maybe i'm not modifying the script right?

Commented:
Make sure you have the Quest AD tools installed (free).
http://www.quest.com/powershell/activeroles-server.aspx

Author

Commented:
Is this the only option? I don't have the quest software installed. I prefer using what i already have, PowerGUI or using the Microsoft exchange shell.

Commented:
JPVG,

You can have those installed side by side.  The Quest AD stuff is great - It will really open your options for scripts.  And it is free.

Perhaps other members have a way to do it with the tools you want to use.  I am sorry I cannot be of more help.


Author

Commented:
Thanks wdurrett. I'm not 100% sure but i think it will query the AD user last logon and not the actual last log on to the exchange mailbox. Again, i might be wrong on this.

Commented:
You can always just run this:

Get-MailboxStatistics -Server  servername | out-file textfilename.txt

from the EMS

Author

Commented:
The output does not give me the mailbo e-mail address.

Author

Commented:
I'm also missing the mailbox size in Kilobits.

Author

Commented:
Does anyone else have any input on my question?
Commented:
Please give the Quest cmdlts a try.  It will do exactly what you want.

http://www.quest.com/powershell/activeroles-server.aspx