【问题标题】:List of users to match a list of job titles in AD与 AD 中的职位列表匹配的用户列表
【发布时间】:2017-01-29 10:18:54
【问题描述】:

我有一个 csv 文件中的职位列表,需要将这些与 AD 中拥有该职位的任何用户匹配。

CSV 内容是这样的:

JobTitle1
JobTitle2
JobTitle3

以下命令将用于获取标题为 JobTitle1 的所有用户的列表:

Get-ADUser -Filter "Title -like 'JobTitle1'"

但是我不能让它将 CSV 文件作为数组使用,它不返回任何输出:

$Titles = Get-Content -Path "c:\jobtitles.csv"  
ForEach ($Title In $Titles)
{
    Get-ADUser -Filter {Title -like '$Title'} 
}

【问题讨论】:

    标签: arrays powershell csv active-directory


    【解决方案1】:

    在 PowerShell 中,单引号内的变量不会被填充,因此您必须改用 双引号 - 或者只是 省略 它们:

    $Titles = Get-Content -Path "c:\jobtitles.csv"  
    ForEach ($Title In $Titles)
    {
        Get-ADUser -Filter {Title -like $Title} 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-12
      • 1970-01-01
      • 2019-11-30
      • 2021-07-12
      • 1970-01-01
      相关资源
      最近更新 更多