You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PnP PowerShell中Get-PnPAzureADUser传变量报错Request_UnsupportedQuery求助

解决PnP PowerShell中变量传入Get-PnPAzureADUser Filter的问题

直接使用脚本块传递带变量的Filter会导致OData查询格式错误,Azure AD无法识别。以下是两种正确的实现方式:

方法1:预先构建Filter字符串

$targetMail = "test@test.com"
$filterQuery = "AccountEnabled eq true and Mail eq '$targetMail'"
Get-PnPAzureADUser -Filter $filterQuery

方法2:直接使用字符串插值

$targetMail = "test@test.com"
Get-PnPAzureADUser -Filter "AccountEnabled eq true and Mail eq '$targetMail'"

问题原因

当使用{AccountEnabled eq true and Mail eq $rrr}这种脚本块形式时,PowerShell不会自动为变量值添加单引号,导致最终发送给Azure AD的OData查询缺少必要的字符串引号,触发Request_UnsupportedQuery错误。而直接用字符串形式构建Filter,能确保邮箱地址被正确包裹在单引号中,符合OData查询的语法要求。

内容的提问来源于stack exchange,提问作者John John

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 19:15:52