【问题标题】:Enable-ADAccount : Cannot validate argument on parameter 'Identity'Enable-ADAccount:无法验证参数“身份”上的参数
【发布时间】:2019-08-26 21:45:23
【问题描述】:

大家好,我正在尝试消除此错误,当我运行以下 powershell 脚本时,我有一个 users.csv 文件应该创建一个新用户。我收到此错误并且对如何修复它感到困惑。感谢阅读

  1. 第一段代码是我在 powershell 中运行时发生的情况
  2. 第二段代码是 powershell 脚本
  3. 是 usres 文件

错误:

Please enter the desired password for 'CN=Kevin,CN=Users,DC=ICS021,DC=local'
Password: Repeat Password: Enable-ADAccount : Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and then try running t
he command 
again.
At C:\Users\Administrator\Desktop\users.ps1:6 char:34
+     Enable-ADAccount  -Identity  $user.Identity
+                                  ~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Enable-ADAccount], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.EnableADAccount

代码:

$users  =  Import-CSV  "C:\Users\Administrator\Desktop\users.csv"
ForEach  ($user  in  $users) {
    $securepwd  =  ConvertTo-SecureString  -String  $user.'password' -AsPlainText  -Force
    New-ADUser  -Name  $user.Name  -GivenName  $user.'Given Name'  -Surname  $user.Surname -SamAccountName  $user.'SamAccountName'
    Set-ADAccountPassword  -Identity  $user.SamAccountName  -Reset  -NewPassword  $user.NewPassword 
    Enable-ADAccount  -identity  $user.identity
}

CSV:

Name,Given Name,Surname,SamAccountName,UserPrincipalName,Password
Kevin,Belanger,KB,2019,2019,password

【问题讨论】:

  • 您的 CSV 中没有身份列,因此在导入 CSV 时没有创建身份属性。将 $user.identity 更改为 $user.samaccountname。
  • 您的 CSV 文件的标题行错误。它说Surname = KB ...我敢打赌这不正确。 [咧嘴]
  • @Lee_Dailey 我认为 Name 的值丢失或 Name 应该被删除。 Userprincipalname 也可能是错误的。
  • @AdminOfThings - 是的,看起来Name 应该是用户名或者可能是显示名。 [咧嘴]

标签: windows powershell command


【解决方案1】:

尝试替换

Enable-ADAccount  -identity  $user.identity

通过

Enable-ADAccount  -identity  $user.SamAccountName

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-03
    • 2023-02-23
    • 2017-06-09
    • 2019-06-01
    • 1970-01-01
    • 2021-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多