我有一个具有以下属性的 Microsoft Graph 用户:
"onPremisesExtensionAttributes": {
"extensionAttribute1": "attr1",
"extensionAttribute2": null,
"extensionAttribute3": null,
"extensionAttribute4": null,
etc.
},
我似乎找不到任何有关如何过滤此属性的文档或示例。我试过了:
https://graph.microsoft.com/beta/users?$filter=extensionAttribute1 eq 'attr1'
https://graph.microsoft.com/beta/users?$filter=onPremisesExtensionAttributes/extensionAttribute1 eq 'attr1'
https://graph.microsoft.com/beta/users?$filter=onPremisesExtensionAttributes/any(x:startswith(x,'attr1'))
所有这些都会导致错误请求,所以显然出了问题。
"code": "BadRequest",
"message": "Invalid filter clause",
问题:如何针对 onPremisesExtensionAttributes 或包含命名属性列表的任何其他属性(例如,extensionAttribute1...n)格式化过滤器? 对于字符串列表(例如 proxyAddresses),您可以这样做:
$filter=proxyAddresses/any(x:startswith(x,%27smtp:myemail%27))
您现在可以过滤
onPremisesExtensionAttributes
:
https://graph.microsoft.com/v1.0/users?$count=true&$filter=onPremisesExtensionAttributes/extensionAttribute1 eq 'attr1'
需要注意的两个要点:
ConsistencyLevel
HTTP 请求标头设置为 eventual
。否则,您将收到 400
状态代码,并显示以下消息 Property 'extensionAttribute1' does not exist as a declared property or extension property.
$count=true
,否则您将收到 400
状态代码,并显示以下消息 Property 'extensionAttribute1' does not exist as a declared property or extension property.
很好用 如果您使用的是 powershell 和 ms graph api(google howto toke 有效)
$headers = @{
"Authorization" = "Bearer $token"
"ConsistencyLevel" = "eventual"
}
# API Endpoint
$uri = "https://graph.microsoft.com/v1.0/users?`$count=true&`$select=displayName,id,department,jobtitle,extensions&`$filter=(onPremisesExtensionAttributes/extensionAttribute1 eq 'VALUE')"
# Make the API call
try {
$response = Invoke-RestMethod -Uri $uri -Headers $headers -Method Get
} catch {
Write-Host "Some Error";
Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
Continue
}