python - 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
}
}
解决方案
试试这个,让我知道它是怎么回事:首先在你的 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`
}
推荐阅读
- powershell - 在 PowerShell 中编写 cp -a 的简单方法
- android - 在 Android Emulator 上通过 ADB 清除“Shell”存储
- flask - 如何使用 pytest 测试 Flask 视图上下文和模板?
- php - 使用 post 方法在 db 表上使用 select 并在同一页面中获取结果
- dart - 如何关闭 receivePort 以使 .toList() 方法正常工作?
- javascript - 已经在服务器上呈现的页面具有 Jquery 事件处理在 React 中不起作用
- javascript - Rails/Webpack:无法访问 JS 库
- python-3.x - 在 Windows 10 上构建 Azure-iot-Hub Python-SDk。如何设置 BOOST 和 cmake 的路径
- java - 417 使用 RestTemplate 进行 POST 请求时期望失败
- python - 在多列上施加层次结构,根据其他列更改列值的随机数