“无法验证参数'Identity'的参数”同时更改多个用户的描述 [英] "Cannot validate argument on parameter 'Identity'" while changing the description for multiple users
本文介绍了“无法验证参数'Identity'的参数”同时更改多个用户的描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的脚本,可以为AD中的用户更改部分说明。
I have a simple script to change part of the description for a user in AD.
Get-ADUser testuser -Properties description | ForEach-Object {
Set-ADUser $_.SamAccountName -Description "ChgDescript,$($_.Description.Split(',')[1])"
}
但是,我现在有700个用户,需要使用上面的命令更改部分说明。我无法正确找出脚本以导入.csv文件并对其执行脚本。
However, I now have 700 users, where I need to change part of the description, using the command above. I'm unable to figure out the script correctly to import the .csv file and run the script against it.
$csvFile = "path_is_here"
Import-Module ActiveDirectory
Import-Csv $csvFile | Get-ADUser -Properties description | ForEach-Object {
Set-ADUser $_.SamAccountName -Description "ChgDescript,$($_.Description.Split(',')[1])"
}
运行上面的脚本时,出现以下错误:
When I run the script above, I receive the following error:
无法验证参数'Identity'的参数。
Cannot validate argument on parameter 'Identity'.
推荐答案
可能您必须先将描述存储在变量中,例如:
May you have to store the description in a variable before, like:
Get-Content users.txt | Get-ADUser -Prop Description | Foreach {
$desc = $_.description + " Disabled 21122012 123456"
Set-ADUser $_.sAMAccountName -Description $desc
}
(仅从 technet )
这篇关于“无法验证参数'Identity'的参数”同时更改多个用户的描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文