Office 365 PowerShell Command for Query

I need an Office 365 PowerShell command line to query for the following users:

UserPrincipalName -like "@Home.net" and extensionAttribute -eq "Green" -and Title -eq "Red" or "Green" and Dept -eq "Red" or "Green" or -eq <empty>  (in other words, the department  field is 'blank'
Anthony K O365Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vasil Michev (MVP)Commented:
The query you are trying to use is inconsistent. User objects do not have extensionattributes, those are added by the Exchange schema so are only available for cmdlets such as Get-Mailbox or Get-Recipient. So you can start by something like this:

Get-MsolUser | ? {$_.UserPrincipalName -like "*@domain.com" -and ($_.Title -in ("Red","Green")) -and ($_.Department -in ("Red","Green",$null))}

Open in new window


The same operation can also be done via the Exchange cmdlets, but it will only return objects Exchange knows about:

Get-User -Filter {UserPrincipalName -like "*@domain.com" -and (Title -eq "Red" -or Title -eq "Green") -and (Department -eq "Red" -or Department -eq "Green" -or Department -eq $null)}

Open in new window


Then if you want to additionally filter using the extensionattributes, use something like:

 Get-Recipient -Filter {CustomAttribute12 -eq "blabla"}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anthony K O365Author Commented:
Sorry, I meant Title must Not equal "Red" or "Green"  and Dept must NOT equal "Red" or "Green" or blank
0
Vasil Michev (MVP)Commented:
So just change it to -ne in the above examples, or put the -not operator in front of the expressions.
0
Anthony K O365Author Commented:
Excellent! This is what I needed. Can you suggest a article that explains these various operators?
0
Anthony K O365Author Commented:
Excellent! Thanks much!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.