我有一个简单的脚本,可以为AD中的用户更改部分说明。
Get-ADUser testuser -Properties description | ForEach-Object {
Set-ADUser $_.SamAccountName -Description "ChgDescript,$($_.Description.Split(',')[1])"
}
但是,我现在有700个用户,我需要使用上面的命令更改部分描述。我无法正确找出该脚本以导入.csv文件并对其执行脚本。
$csvFile = "path_is_here"
Import-Module ActiveDirectory
Import-Csv $csvFile | Get-ADUser -Properties description | ForEach-Object {
Set-ADUser $_.SamAccountName -Description "ChgDescript,$($_.Description.Split(',')[1])"
}
当我运行上面的脚本时,出现以下错误:
Cannot validate argument on parameter 'Identity'.
最佳答案
可能您需要先将描述存储在变量中,例如:
Get-Content users.txt | Get-ADUser -Prop Description | Foreach {
$desc = $_.description + " Disabled 21122012 123456"
Set-ADUser $_.sAMAccountName -Description $desc
}
(仅从technet复制)
关于powershell - “Cannot validate argument on parameter '更改多个用户的描述时的身份'”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35141014/