我想让这行很长,以便阅读:
$Params = @{
Server = 'example.com:3268'
Filter = '{ EmailAddress -eq $Mail }'
Properties = 'CN,co,Company,Department,DisplayName,SamAccountName,State,Office,EmailAddress'
}
Get-ADUser @Params
我读到使用喷溅效果很好,所以我正在尝试:
Ende
但是运行它会引发错误:
Get-ADUser : Error parsing query: '{ EmailAddress -eq stantastic@example.com }' Error Message: 'syntax error' at position: '1'. At line:1 char:1 + Get-ADUser @Params + ~~~~~~~~~~~~~~~~~~ + CategoryInfo : ParserError: (:) [Get-ADUser], ADFilterParsingException + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADFilterParsingException,Microsoft.ActiveDirectory.Management.Commands.GetADUser
我想念什么?
答案 0 :(得分:4)
您应该将过滤器作为ActiveDirectory
传递到string
模块cmdlet。您无需在代码中加入方括号:
Get-ADUser -Filter "EmailAddress -eq '$Mail'"
尽管您可以通过scriptblock
,但无论如何它都隐式地变成了string
。此外,当期望<{1}}的 string
时,您将作为单个array
传递属性。
正确的方法:
string
我建议检查$aduserParams = @{
Server = 'example.com:3268'
Filter = "EmailAddress -eq '$Mail'"
Properties = 'CN', 'co', 'Company', 'Department', 'DisplayName', 'SamAccountName', 'State', 'Office', 'EmailAddress'
}
Get-ADUser @aduserParams
的参数类型:
Get-Help