Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell:导入csv并获取aduser_Powershell_Active Directory - Fatal编程技术网

Powershell:导入csv并获取aduser

Powershell:导入csv并获取aduser,powershell,active-directory,Powershell,Active Directory,我正在尝试查找用户,存储在广告中的“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 Gracia e、 t.c编辑CSV文件,并用双引号将显示名称括起来,如下所示: id "M

我正在尝试查找用户,存储在广告中的“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 Gracia

e、 t.c

编辑CSV文件,并用双引号将显示名称括起来,如下所示:

id
"MacAskill Danny"
"Cedric Gracia"
然后,像这样使用itermediate变量

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
参数传递和解析变量时出现了一些奇怪的情况。

编辑CSV文件并用双引号将显示名括起来,如下所示

id
"MacAskill Danny"
"Cedric Gracia"
# 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 $_' }
然后,像这样使用itermediate变量

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
参数传递和解析变量时出现了一些奇怪的情况。

我知道这是一篇老文章,但它确实为我省去了很多麻烦。无法找到具有导入值的用户,但只需创建一个中间变量,我就可以让脚本正常工作。我甚至不需要用双引号

# 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 $_' }

克里斯

我知道这是一篇老文章,但它确实让我省去了很多麻烦。无法找到具有导入值的用户,但只需创建一个中间变量,我就可以让脚本正常工作。我甚至不需要用双引号


Kris

“%”的位置是什么?使用PS的第一天,它炸了我的大脑…@nuT707,
%
是每个对象的别名。也就是说,它只是一个较短的形式。就像
Where Object
的快捷方式。更多信息:
获取有关别名的帮助。
。“%”的位置是什么?使用PS的第一天,它炸了我的大脑…@nuT707,
%
是每个对象的别名。也就是说,它只是一个较短的形式。就像
Where Object
的快捷方式。更多信息:
获取有关\u别名的帮助