首页 > 解决方案 > Ldap 脚本仅适用于一封电子邮件

问题描述

目前有这个代码,但它没有循环或正常工作。

$path = "D:\users.csv"
$csv = Import-Csv $path 
Import-Module ActiveDirectory

foreach($line in $csv){
    $User = Get-ADUser -LDAPFilter "(&(objectclass=user)(mail=$($line.Email)))"
    If ($User -eq $Null) {
        "User does not exist in AD   " + $line.Email 
    } Else {
        "User found in AD  - " + $line.Email
    }
}

标签: pythonpowershell

解决方案


试试这个,让我知道它是怎么回事:首先在你的 csv 文件中添加标题名称,然后在它下面添加所有要添加的用户。命名 John Nancy 等...然后为 powershell

$file = "D:\users.csv"
$inputs = Import-Csv -path $file |select -expandproperty Name
foreach($input in $inputs){
your rest of code here...`enter code here`
} 

推荐阅读