I'm brewing on a command to show all mailboxes which have a LastLogonTime -60 from now
I'm running into some problems. I have a working command:
Get-MailboxStatistics -Server <mail server> | where {$_.ObjectClass -eq "Mailbox"} | Sort-Object LastLogonTime -Descending | ft @{label="User";expression={$_.DisplayName}},@{label="Total Size (MB)";expression={$_.TotalItemSize.Value.ToMB()}},@{label="Items";expression={$_.ItemCount}},@{label="LastLogonTime";expression={$_.LastLogonTime}} -auto
It returns the following: User Total Size (MB) Items LastLogonTime ---- --------------- ----- -------------
i want 2 things.
First a want a complete list of the entire exchange, not per server (we have 20+ server with 4 datastores per server) Second, i want to show only the item with LastLogonTime from 60 days and older ((Get-Date).AddDays(-60))
I only get some junk in return when i try to insert the LastLogonTime -lt ((Get-Date).AddDays(-60))
I changed the script up a bit to get it to work. This is what I've gotten and it'll provide the information I believe that you're looking for. It returns mailboxes with No Lastlogon date, as well as, over 60 days. I'm passing in variable instead of trying to define it in the powershell statement itself.
No Sorting or label changes have been made so you should be able to tweak it to meet your requirements.There is a bit of a piping issue here if you use EMS instead of loading the snapin with powershell, so here's an articular to reference if you run into that.
I have corrected the powershell query as you suggested to collect against all servers with a role matching *Mailbox* and matching mailboxes where logins have not occurred in the last 60 days. i then formatted your output to contain the server name and the server role since the output can be very long, in addition the fields you you require