gpt4 book ai didi

powershell - 泼溅不适用于参数 -Filter

转载 作者:行者123 更新时间:2023-12-02 23:01:00 24 4
gpt4 key购买 nike

我有这么长的一行,我想让它更容易阅读:

$Mail = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="156661747b617466617c7655706d74786579703b767a78" rel="noreferrer noopener nofollow">[email protected]</a>"    
Get-ADUser -Server example.com:3268 -Filter {EmailAddress -eq $Mail} -Properties CN,co,Company,Department,DisplayName,SamAccountName,State,Office,EmailAddress

我读到使用泼溅效果很好,所以我正在尝试:

$Params = @{
Server = 'example.com:3268'
Filter = '{ EmailAddress -eq $Mail }'
Properties = 'CN,co,Company,Department,DisplayName,SamAccountName,State,Office,EmailAddress'
}

Get-ADUser @Params

但是运行它会引发错误:

Get-ADUser : Error parsing query: '{ EmailAddress -eq [email protected] }' 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

我错过了什么?

最佳答案

您应该将过滤器作为字符串传递给ActiveDirectory模块cmdlet。您在代码中不必要地包含括号:

Get-ADUser -Filter "EmailAddress -eq '$Mail'"

虽然您可以传递脚本 block ,但它无论如何都会隐式转换为字符串。此外,当需要 string数组时,您会将属性作为单个string 传递。 p>


正确的做法:

$aduserParams = @{
Server = 'example.com:3268'
Filter = "EmailAddress -eq '$Mail'"
Properties = 'CN', 'co', 'Company', 'Department', 'DisplayName', 'SamAccountName', 'State', 'Office', 'EmailAddress'
}
Get-ADUser @aduserParams

我建议检查Get-Help参数类型:

Get-ADUser -Filter <string>
[-ResultPageSize <int>]
[-ResultSetSize <System.Nullable[System.Int32]>]
[-SearchBase <string>]
[-SearchScope {Base | OneLevel | Subtree}]
[-AuthType {Negotiate | Basic}]
[-Credential <PSCredential>]
[-Partition <string>]
[-Properties <string[]>]
[-Server <string>]
[<CommonParameters>]

关于powershell - 泼溅不适用于参数 -Filter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55145423/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com