microsoftgraph/msgraph-sdk-powershell

Get-MGUser Cannot filter on the companyName property

Closed this issue · 2 comments

Describe the bug

I an trying to filter user by the company name.

Get-MGuser -Filter "companyName eq 'XYZ'"

This results in the error message:
Unsupported or invalid query filter clause specified for property 'companyName' of resource 'User'.

MS Documentation states that this property is filterable on.

Expected behavior

This property should be filterable, this is an important property in Active Directory EntraID directories.

How to reproduce

Execute Get-MgUser -Filter "Department eq 'Finance' and CompanyName eq 'xyx'"

This produces the result:
Get-MgUser_List: Unsupported or invalid query filter clause specified for property 'companyName' of resource 'Use

SDK Version

2.20.0

Latest version known to work for scenario above?

None

Known Workarounds

Use a Where-Object clause. This is inefficient as you will need to return the entire user list to the client. A filter would be much more efficient.

Debug output

There is no -debug parameter on Get-MGUser

Configuration

Name Value


PSVersion 7.4.4
PSEdition Core
GitCommitId 7.4.4
OS Fedora Linux 40 (Cinnamon)
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

Other information

No response

@Clifra-Jones thank you for logging this issue. However, based on the advanced odata queries documentation here, this seems to be an API limitation where $filter query parameter can only be used on a selected set of properties. (See image below).
image

Since this is not primarily an SDK issue, I will close it and suggest that you kindly raise an issue here https://developer.microsoft.com/en-us/graph/support so that the API owner can respond to it. Also, this is the command that worked for me which you can try it out. Get-MgUser -CountVariable CountVar -Filter "CompanyName eq '<Your company name>'" -ConsistencyLevel eventual.

Interesting that $filter seems to limit the valid fields. When looking at the documentation for CompanyName it indicated that filter eq should work.