You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用DisplayName获取SamAccountName时出现筛选器无法识别错误

解决方法

先排查文件格式问题

你用了Import-Csv但输入的是txt文件——如果这个文件不是CSV格式(没有表头DisplayName,只是每行一个用户名),得换成Get-Content读取:

Get-Content C:\Temp\studentlookup.txt | ForEach {
    $displayName = $_
    Get-ADUser -Filter { DisplayName -eq $displayName } -Properties Name, SamAccountName, City, co, DistinguishedName | 
        Select-Object Name, SamAccountName, City, co, DistinguishedName
} | Export-Csv -Path C:\Temp\studentresult.csv -NoTypeInformation

如果是带表头的CSV格式文件

原脚本的过滤器写法容易因为DisplayName包含特殊字符(比如单引号)导致语法错误,换成哈希表格式的过滤器更稳定:

Import-Csv C:\Temp\studentlookup.txt | ForEach-Object {
    Get-ADUser -Filter @{ DisplayName = $_.DisplayName } -Properties Name, SamAccountName, City, co, DistinguishedName | 
        Select-Object Name, SamAccountName, City, co, DistinguishedName
} | Export-Csv -Path C:\Temp\studentresult.csv -NoTypeInformation

额外注意事项

  • 确保执行脚本的账号拥有AD查询权限
  • 如果存在DisplayName重名的用户,会返回多个结果,可添加-SearchBase参数指定特定OU范围缩小查询范围

内容的提问来源于stack exchange,提问作者Shelly

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 15:42:34