Weird -filter issue

So, I’m trying to get a list of mailboxes that are shared but do not have the “Termed” retention policy. When I run this command:

Get-Mailbox -ResultSize unlimited -Filter {(RecipientTypeDetails -eq 'SharedMailbox') -and (RetentionPolicy -ne 'Termed')} | select name,retentionpolicy

it still pulls in the “Termed” retentionpolicy users. However, if I run this command:

Get-Mailbox -ResultSize unlimited -Filter {(RecipientTypeDetails -eq 'UserMailbox') -and (UsageLocation -ne 'Korea')} | select name, usagelocation

it doesn’t pull in any of the mailboxes located in Korea (I let this run for a couple minutes just to make sure).

Am I missing something?

What version of Exchange are you running? At least for Exchange 2007 through Exchange 2013, RetentionPolicy and UsageLocation are not filterable properties. See for the Exchange 2013 filterable properties article. You can get to the ones for Exchange 2007 & 2010 from there.

Try the following instead:

Get-Mailbox -ResultSize unlimited -Filter {(RecipientTypeDetails -eq "SharedMailbox")} | Where{$_.RetentionPolicy -eq "Termed"} | Select name,retentionpolicy


Get-Mailbox -ResultSize unlimited -Filter {(RecipientTypeDetails -eq "UserMailbox")} | Where{$_.UsageLocation -ne "Korea"} | Select name, usagelocation

I don’t know why this is like tit is but you could try it this way:

Get-Mailbox -ResultSize unlimited -Filter {RecipientTypeDetails -eq ‘SharedMailbox’} |
Where-Object {$_.RetentionPolicy -ne ‘Termed’} |
select name,retentionpolicy

Kevyn - I didn’t even think about the field not being filterable. I’m using O365. I tried the command with only the retentionpolicy and it didn’t work. I did have that workaround but I was trying to be greedy and have the filter do all the work.

Olaf - thank you for your workaround as well.

I’ve also got an O365 tenant. Let me do some testing and see if I can get the filters to work. I’ll try to post back by tomorrow.

UsageLocation is a filterable property in O365, which currently uses Exchange 2016. However, the RetentionPolcy still does not look to be a filterable property. Looks like you’ll have to filter that locally.