• RSS
  • Twitter
  • FaceBook

Exchange Server Forums

Forums | Register | Login | My Profile | Inbox | RSS RSS icon | My Subscription | My Forums | Address Book | Member List | Search | FAQ | Ticket List | Log Out

[Powershell] Get-Mailbox with LastLogonTime -60

Users viewing this topic: none

Logged in as: Guest
  Printable Version
All Forums >> [Microsoft Exchange 2007] >> Management >> [Powershell] Get-Mailbox with LastLogonTime -60 Page: [1]
Login
Message << Older Topic   Newer Topic >>
[Powershell] Get-Mailbox with LastLogonTime -60 - 9.Feb.2012 8:40:24 AM   
bigfoot48

 

Posts: 4
Joined: 26.Jan.2012
Status: offline
Hi Folks,

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))

Can some help me? :)
Post #: 1
RE: [Powershell] Get-Mailbox with LastLogonTime -60 - 9.Feb.2012 11:48:53 AM   
barbyf

 

Posts: 17
Joined: 3.Feb.2012
Status: offline
The first thing you'll want to do is to pipe in the databases to get-mailboxstatistics. This will allow you to get the mailboxes across all servers.

http://technet.microsoft.com/en-us/library/bb124924%28EXCHG.80%29.aspx

get-mailboxdatabase |get-mailboxstatistics

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.

$Days = 60
$TimeLimit = (Get-Date).AddDays(-$Days)
get-mailboxdatabase | get-mailboxstatistics | where-object {(get-mailboxstatistics $_.LegacyDN).LastLogonTime -eq $NULL -or (get-mailboxstatistics $_.LegacyDN).LastLogonTime -lt $TimeLimit} | ft DisplayName, TotalItemSize, ItemCount, LastLogonTime

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.

http://www.mikepfeiffer.net/2010/02/exchange-management-shell-error-pipelines-cannot-be-executed-concurrently/

(in reply to bigfoot48)
Post #: 2
RE: [Powershell] Get-Mailbox with LastLogonTime -60 - 9.Feb.2012 12:05:00 PM   
thehoodedcoder

 

Posts: 3
Joined: 9.Feb.2012
Status: offline
Hi,

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

get-exchangeserver | select-object name, serverrole | where {$_.serverrole -like '*Mailbox*'} | foreach-object {$servernamevar = $_.Name; $serverrolevar = $_.serverrole;
Get-MailboxStatistics -Server $servernamevar | where {$_.ObjectClass -eq "Mailbox"-and $_.LastLogonTime -lt ((get-date).AddDays(-60)) } |
Sort-Object LastLogonTime -Descending | ft @{label="Server Name";expression={$servernamevar}},@{label="Server Role";expression={$serverrolevar}},@{label="User";expression={$_.DisplayName}},@{label="Total Size (MB)";expression={$_.TotalItemSize.Value.ToMB()}},@{label="Items";expression={$_.ItemCount}},@{label="LastLogonTime";expression={$_.LastLogonTime}} -auto }


The script works for both Exchange 2007 and Exchage 2010 target hosts.

Good luck and enjoy.

Thanks,
Kevin

< Message edited by thehoodedcoder -- 9.Feb.2012 1:12:41 PM >


_____________________________

System Engineer:
Systems Governance and Compliance
Unix Data and Access Governance

(in reply to bigfoot48)
Post #: 3

Page:   [1] << Older Topic    Newer Topic >>
All Forums >> [Microsoft Exchange 2007] >> Management >> [Powershell] Get-Mailbox with LastLogonTime -60 Page: [1]
Jump to:

New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Follow TechGenix on Twitter