【发布时间】:2017-08-17 16:47:54
【问题描述】:
我在 PowerShell 中通过 Get-AdUser 命令在多行过滤器表达式中使用反引号(重音符号)时遇到问题。具体来说,我正在 Windows 7 上测试 PowerShell 2.0。
一个工作示例(过滤器都在一行上):
Get-ADUser -Filter {Name -like "Smith*" -and Enabled -eq $True}
# This works as expected, a list of matching objects is returned on pipeline
一个破碎的例子(过滤器被分割成多行):
Get-ADUser -Filter {Name -like "Smith*" `
-and Enabled -eq $True}
# Error message indicates "Operator not supported at position [of backtick]
第二个破例(反引号前带有 -and 的多行过滤器):
Get-ADUser -Filter {Name -like "Smith*" -and `
Enabled -eq $True}
#Error message indicates "Syntax error at position [of backtick]"
请提供解决方法示例或解释不支持这些多行过滤器的原因。我无法弄清楚这一点,但似乎这应该是 PowerShell 中一种简单而常见的操作类型。
【问题讨论】:
标签: powershell escaping multiline backticks