我尝试查找用户,存储在AD的'users.csv‘中:
Import-Module ActiveDirectory
import-csv "\users.csv" | ForEach-Object {
Get-ADUser -Filter {displayname -eq $_.id}}但是PS说找不到'id‘属性
users.csv内容:
id
MacAskill Danny
Cedric Graciae.t.c
发布于 2013-10-07 14:26:59
编辑CSV文件并使用双引号将显示名括起来,如下所示:
id
"MacAskill Danny"
"Cedric Gracia"在此之后,使用迭代中间变量,如下所示:
Import-Csv .\users.csv | % {
$f = $_.id; # Set the displayname into a temp variable
get-aduser -filter { displayname -eq $f } # Use the temp variable with filter
}我不知道为什么需要中间变量。使用-filter参数传递和解析变量时发生了一些奇怪的事情。
发布于 2014-08-15 05:20:43
# Use Import-csv and Get-ADUser together
# Import csv that contains "sn" column and get all AD users where
# sn matches any of the values imported from csv
Import-Csv C:\temp\1.csv | select sn -ExpandProperty sn | foreach { Get-ADUser -Filter 'sn -eq $_' }发布于 2014-12-10 04:52:35
我知道这是一个古老的帖子,但它确实让我省去了很多头疼的事情。我不知道如何找到具有导入值的用户,但只需创建一个中间变量,我就可以让我的脚本工作。我甚至不需要使用任何双引号。
克里斯
https://stackoverflow.com/questions/19217903
复制相似问题