Answered by:
Powershell help

Question
-
I've got the below ps command that shows me all mailboxes that havent been logged into in the last 90 days but Id like to add the WhenCreated parameter from Get-Mailbox, can someone show me how I can add that?
Get-Mailboxserver | Get-MailboxStatistics | where {$_.LastLogonTime -lt (get-date).AddDays(-90)} | select displayName,lastlogontime,lastloggedonuseraccount,servername
Thursday, March 27, 2014 3:49 PM
Answers
-
Ah, good point, Rich. He can also get that before he gets the statistics with the following:
Get-Mailboxserver | Get-Mailbox | % { $Created = $_.DateCreated ; Get-MailboxStatistics $_ | where {$_.LastLogonTime -lt (get-date).AddDays(-90)} } | select displayName, lastlogontime, lastloggedonuseraccount, servername, @{E={ $Created }; L='DateCreated'}
To me, it looks a little cleaner ... But either way will work.
- Edited by Will Martin, PFE Friday, March 28, 2014 11:48 AM
- Marked as answer by Billy902 Friday, March 28, 2014 12:10 PM
Friday, March 28, 2014 11:47 AM -
I think he wants to see the WhenCreated value added to the "select". Adding this to the "select" will do that.
@{n='WhenCreated';e={(get-mailbox $_.LegacyDN).WhenCreated}}
--- Rich Matheisen MCSE&I, Exchange MVP
- Marked as answer by Billy902 Friday, March 28, 2014 12:10 PM
Friday, March 28, 2014 2:26 AM
All replies
-
The Get-Mailbox command allows you to add the -Filter parameter, which you can use with the date created. Try the following:
Get-Mailboxserver | Get-Mailbox -Filter { WhenCreated -gt <date> } | Get-MailboxStatistics | where {$_.LastLogonTime -lt (get-date).AddDays(-90)} | select displayName,lastlogontime,lastloggedonuseraccount,servername
Note that you do NOT need the $_. before the WhenCreated ...
- Edited by Will Martin, PFE Thursday, March 27, 2014 5:08 PM
Thursday, March 27, 2014 5:08 PM -
I think he wants to see the WhenCreated value added to the "select". Adding this to the "select" will do that.
@{n='WhenCreated';e={(get-mailbox $_.LegacyDN).WhenCreated}}
--- Rich Matheisen MCSE&I, Exchange MVP
- Marked as answer by Billy902 Friday, March 28, 2014 12:10 PM
Friday, March 28, 2014 2:26 AM -
Ah, good point, Rich. He can also get that before he gets the statistics with the following:
Get-Mailboxserver | Get-Mailbox | % { $Created = $_.DateCreated ; Get-MailboxStatistics $_ | where {$_.LastLogonTime -lt (get-date).AddDays(-90)} } | select displayName, lastlogontime, lastloggedonuseraccount, servername, @{E={ $Created }; L='DateCreated'}
To me, it looks a little cleaner ... But either way will work.
- Edited by Will Martin, PFE Friday, March 28, 2014 11:48 AM
- Marked as answer by Billy902 Friday, March 28, 2014 12:10 PM
Friday, March 28, 2014 11:47 AM -
This is perfect, thank you.Friday, March 28, 2014 12:11 PM