Enable-ADAccount:无法验证参数'Identity'的参数

问题描述 投票:0回答:1

嘿家伙我正在试图摆脱这个错误,我有一个users.csv文件应该创建一个新用户,当我运行以下powershell脚本。我收到此错误,并对如何解决它感到困惑。谢谢阅读

  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
windows powershell command
1个回答
0
投票

尝试更换

Enable-ADAccount  -identity  $user.identity

通过

Enable-ADAccount  -identity  $user.SamAccountName
© www.soinside.com 2019 - 2024. All rights reserved.