I'm trying to make list with searchbox in powershell winforms, and it's partitially working. When I have several items containing inserted phrase it works perfectly but when i have only one result, program shows me number of something, but I don't know what is it. It looks like below:
2-found several items - still ok
$pharmacies = Get-ADComputer -searchbase "OU=xxx,OU=Servers,OU=PL,OU=_Production,DC=xxx,DC=xxx" -Filter {Description -like "*"} -properties ComputerName, Department, Description
...
$listSearchBox.Add_TextChanged({
$listBox.Items.Clear()
$toFind = '*' + $listSearchBox.text + '*'
$search = $pharmacies | where Description -like $toFind
if($search.count -lt 1){
[void] $listBox.Items.Add('Brak wyników') #no results
}else{
$searchCounter = 0
do{
$listBox.Items.Add($search.description[$searchCounter])
$searchCounter++
}until($searchCounter -eq @($search).Count )
}
})
so i think the problem is somewhere in array, which get data from AD but I don't know where, because when I prepared "static" array for ex:
$pharmacies = @('123 - xxx Medyczna 1','256 - yyyyyy Medyków 1', '615 - zzzz Fabryczna 256')
all searching results was correctly shown
THX in advance for help :)