jarred power
jarred power

Reputation: 13

Piping Get-mailbox -filter into Get-mailboxstatistics -filter

I'm trying to filter a list with two commands - Filter by Attribute then filter by "not disconnected" and "logged in in the last 90 days." Trying something like this, but it's not working.

get-mailbox -filter 'ExtensionCustomAttribute1 -eq $null'| Get-MailboxStatistics -filter {DisconnectDate -eq $null -and LastLogonTime -gt (get-date).adddays(-90)}

When I run;

get-mailbox -filter 'ExtensionCustomAttribute1 -eq $null' | Get-MailboxStatistics

I get the first part of the results with the info I'm looking for - I just can't filter this list further. ie adding -filter does not work.

The result is:

Results of code

Upvotes: 1

Views: 2245

Answers (2)

Ezzi
Ezzi

Reputation: 131

I'd say the best solution to your problem is to filter via where-object as stated earlier.

The below should work out for you, it has not been tested but should be correct.

Get-Mailbox -Filter 'ExtensionCustomAttribute1 -eq $null' | Get-MailboxStatistics | where {$_.DisconnectDate -eq $null -and $_.LastLogonTime -gt (Get-Date).AddDays(-90)}

Upvotes: 1

Jacob Colvin
Jacob Colvin

Reputation: 2835

Technet documentation specifies that filters must be done using single quotes, not curly braces.

-Filter 'DisconnectDate -ne $null'

Is the example given here: https://technet.microsoft.com/en-us/library/bb124612(v=exchg.160).aspx

I've run into this issue before when filtering AD users. I have to assume that they changed their standard at some time during the past.

If you don't have success with this, you can try using where-object to filter to the right... i.e.:

Get-MailboxStatistics | ?{$_.DisconnectDate -ne $null}

Obviously use the former if it works.

Upvotes: 0

Related Questions