powershell - Get-AzureADUser 过滤器 - “没有输入就无法评估脚本块”
问题描述
有人可以向我解释为什么以下工作:
$email = 'fred@bloggs.com'
Get-ADUser -Filter {mail -eq $email}
但是当我这样做时:
$email = "fred@bloggs.com"
Get-AzureADUser -Filter {mail -eq $email}
我得到:
Get-AzureADUser : Cannot evaluate parameter 'Filter' because its argument is specified as a script block and there is no input. A script block cannot be evaluated without input.
谢谢。
解决方案
这两个命令使用两种不同类型的过滤器。
Get-ADUser
使用 PowerShell 表达式语言语法。{}
即使在技术上不应该使用它们,它也可以接受周围环境,因为它不是真正的脚本块。这也意味着您可以使用 , 等 PowerShell 运算符的子集。-eq
此-like
过滤器的正确语法是"mail -eq '$email'"
. 内部引号是必需的,因为 PowerShell 会在将字符串传递给之前扩展双引号内的字符串Get-ADUser
,这将导致mail -eq user@domain.com
(注意电子邮件地址周围没有引号)并引发错误。
Get-AzureADUser
使用 oData v3.0 过滤器语句。该规范不允许 PowerShell 运算符语法,因为它有自己的规则。它现在也允许使用 scriptblock ( {}
) 语法。构造此过滤器的正确方法是-Filter "mail eq '$email'"
. 注意它使用eq
而不是-eq
. 使用 oData 过滤器,您可以访问可以更轻松地检索和操作数据的功能。使用函数的一个例子是Get-AzureADUser -Filter "startswith(Mail,'$email')"
。
请参阅Get-ADUser-Filter
以查看有关Get-ADUser
.
请参阅Get-AzureADUser以查看有关该Get-AzureADUser -Filter
参数的更多信息。
附加链接oData Filter Querying Collections包含一个可接受的运算符和函数表,以添加重要的查询功能。
推荐阅读
- fullcalendar - fullcalendar nextDayThreshold 不起作用。'00:00:00' 显示的时间少了一天
- reactjs - React 挂钩如何从子 Form.Control 设置对 InputGroup 的关注
- python - 有没有办法在不安装其他任何东西的情况下从音频文件中删除/编辑名为“标签”的元数据条目?
- python - 如何在执行任何语句之前调用连接方法
- google-cloud-platform - Google 部署管理器 - 数据库创建失败
- powershell - 具有多个值的 Switch-Case
- apache - 无法使用本地主机端口 80;启动用户级代理时出错:绑定 0.0.0.0:80:意外错误(EADDRINUSE 失败)
- python-3.x - 在 groupby 之后对同一列应用多个操作
- java - Jhipster 网关直接调用微服务
- xaml - UWP TreeView 编辑数据绑定树项节点