我有在PowerShell中使用Get-AdUser命令對多行過濾器表達式使用反斜槓(重音符號)時遇到問題。具體而言,我在Windows測試PowerShell的2.0 7.反向PowerShell中的Get-ADUser多行過濾器
工作示例(濾波器是全部在一行):
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中一種簡單而常見的操作類型。
你好@Matt,這幫助我得到了一個可接受的解決方法。我不必創建一個單獨的腳本塊。僅僅結束每一行就足夠了,並且讓解析器尋找更多(我認爲?)。它不會讓我把多行代碼放在評論中 - 試圖找出把它放在哪裏... –