I've been trying to get usernames using employee numbers but have run into an issue. The code below works if I enter 1 employee number in the textbox but as soon as there is more than 1 employee number in the textbox, it throws a "cannot index into a null array" error and fetches none but the last username in the array.
The usernames are entered into the textbox in the following format:
Employee1
Employee2
Employee3
If I use Write-Host to print the array items before the search function then it is all fine. But as soon as the adsisearcher part is used, I get an null array error. Can anyone kindly help with this? and explain where I am going wrong?
$array = $textboxL.Text.Split("`n")
foreach($item in $array){
$adString = (([adsisearcher]"(&(objectCategory=User)(employeenumber=$item))").findall()).properties["mailnickname"]
$textBoxR.AppendText("$adString`r`n")
}