I did an Ad bulks script but doesn't seem to work for some reason. can someone help me ?
$ADUsers = Import-csv C:\Users\Deng\Desktop\newusers.csv
foreach ($User in $ADUsers)
{
$Username = $Users.username
$Firstname = $Users.firstname
$Password = $Users.password
$Lastname = $Users.lastname
$OU = $Users.ou
New-ADUser `
-SamAccountName $Username `
-UserPrincipalName [email protected] `
-Name $Firstname $Lastname `
-GivenName $Firstname `
-Surname $Lastname `
-Enabled $True `
-ChangePasswordAtLogon $false `
-DisplayName $Lastname, $Firstname `
-Path $OU `
-AccountPassword (convertto-securestring $Password -AsPlainText -Force)
}
I get this error below :
ConvertTo-SecureString: Cannot bind argument to parameter 'String' because it is null. At line:24 char:54 + ... -AccountPassword (convertto-securestring $Password -AsPlai ... + ~~~~~~~~~ + CategoryInfo : InvalidData: (:) [ConvertTo-SecureString], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertToSecureStringCommand
also see the content of the CSV
usersname firstname password lastname ou
efranklin Edward P@s$word Franklin "OU=PII Users,DC=PII,DC=net"
bjackson Bill P@s$word Jackson "OU=PII Users,DC=PII,DC=net"
I have made the change and this is what i get – DavidNG
ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null. At line:24 char:54 + ... -AccountPassword (convertto-securestring $Password -AsPlai ... –
still getting the same error
$Users
? – CaramirielImport-Csv
cmdlet as parameter-Delimiter ' '
and take the advice from @Steven to use Splatting to get rid of those horrible backticks. – Theo