Jump to content

Recommended Posts

Posted

Hi, a simple Q:

 

I can list all mailboxes starting with 22xxxxx or 21xxxxxxxx with this -like filter:

Get-Mailbox -ResultSize Unlimited | where-object { $_.Name -like "22*" -or $_.Name -like "21*"}

 

 

but to get the opposite, excluding all mailboxes containing 22xxxxx or 21xxxxxxxx I thought just to use -notlike, but it returns all the mailboxes.

Get-Mailbox -ResultSize Unlimited | where-object { $_.Name -notlike "22*" -or $_.Name -notlike "21*"}

 

 

Any advice would be great.

 

Thanks

Posted

Its because you're using "or". "22*" are notlike 21 so are included, and "21*" and notlike 22 so are included. You need parentheses.;

 

Get-Mailbox -ResultSize Unlimited | Where-Object { -not ($_.Name -like "22*" -or $_.Name -like "21*") }

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...