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?
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.