powershell - “Cannot validate argument on parameter '更改多个用户的描述时的身份'”

标签 powershell active-directory

我有一个简单的脚本,可以为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/

相关文章:

powershell - 搜索事件日志消息的最有效方法

c# - 为什么域用户获得 UnauthorizedAccessException 并授予 "Everyone"读写权限?

variables - 如何使用PowerShell变量作为命令参数?

windows - 是否可以在 Windows 命令行上撤消粘贴?

java - 如何使 LDAP 过滤器在 OU 的三个级别中查找值

c++ - 传递给 LogonUser() 的密码不正确,但 Active Directory 帐户未按预期锁定

c# - Azure Active Directory 身份验证出现错误 "we can' 无法连接到您现在需要的服务”

c# - 替换 proxyAddresses 值

powershell - Azure 自动化获取-AzureRmStorageAccountKey

powershell - 如何枚举给定文件或文件夹的卷影副本?