Powershell基于CSV更改广告字段

时间:2014-02-05 16:02:13

标签: powershell csv scripting powershell-v2.0

将CSV格式化为

User     Department
myname   test1
yourname test1  

有脚本:

$data = import-csv c:\ad.csv
$data |% { 
set-qaduser $_.$User -department $_.department
}

导入工作正常,但我无法进行字段更改,不断收到错误:

Set-QADUser : Cannot validate argument on parameter 'Identity'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
At line:3 char:12

任何人都能引导我朝着正确的方向前进吗?

1 个答案:

答案 0 :(得分:0)

$_.$User周围有一个额外的角色。它应该是$_.User

$data = import-csv c:\ad.csv;
$data |% { 
    Set-QADUser -Identity $_.User -Department $_.department;
}