petben Posted August 17, 2023 Posted August 17, 2023 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
Jawloms Posted August 17, 2023 Posted August 17, 2023 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*") } 1
Jawloms Posted August 17, 2023 Posted August 17, 2023 Not wishing to put EduGeek out of business, but I literally copied your post and pasted it in to chatgpt. I can take no real credit. 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now