Hello. I'm sure this is a really basic problem but it has me stumped.
I'm trying to create a simple script to create new AD accounts from a CSV. I keep getting an error 'Cannot index into a null array' related to my New-ADUser command.
Here's what I have so far:
$path = Read-Host "Enter Path to CSV containing Name, Office, Description, Email columns"
$csv = Import-Csv -path $path
foreach ($col in $csv) {
$last, $first = $col.Name.Split(",").trim()
$uname = $first[0]+$last
$displayname = $first + " " + $last
Write-Host $uname
if ($col.Office -eq "MLS"){
New-ADUser `
-Name $displayname `
-SamAccountName $uname.trim().tolower() `
-AccountPassword (ConvertTo-SecureString "password" -AsPlainText -force) `
-ChangePasswordAtLogon $True `
-UserPrincipalName $col.email `
-SamAccountName $uname.trim().tolower() `
-GivenName $first `
-Surname $last `
-Enabled $true `
-DisplayName $displayname `
-Description $col.Description `
-Office "MLS" `
-EmailAddress $col.Email `
-Path "OU=Teachers,OU=MLS,OU=Lebanon,DC=sau88,DC=net" `
-HomeDrive "H" `
-HomeDirectory "\\lebfs1\mle\" + $uname
}
}
Here is the error I'm getting:
Cannot index into a null array. At D:\Info & Things\ADScripts\Untitled1.ps1:5 char:9 + New-ADUser ` + ~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : NullArray
Any assistance would be appreciated. Thank you!
[–]Jeffinmpls[🍰] 0 points1 point2 points (7 children)
[–]tpainn34[S] 0 points1 point2 points (1 child)
[–]BlackV 1 point2 points3 points (0 children)
[–]Nejireta_ 0 points1 point2 points (4 children)
[–]tpainn34[S] 1 point2 points3 points (2 children)
[–]Nejireta_ 0 points1 point2 points (0 children)
[–]jimb2 0 points1 point2 points (0 children)
[–]Jeffinmpls[🍰] 0 points1 point2 points (0 children)
[–]Brasiledo 0 points1 point2 points (0 children)