0

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:

1-found several items - ok

2-found several items - still ok

3-fault

4-found no items - 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 :)

cr4ces
  • 1
  • [PowerShell gotcha 4a](https://stackoverflow.com/a/69644807/1701026)? Try: `$listBox.Items.Add(@($search.description)[$searchCounter])` – iRon Apr 29 '22 at 10:42
  • Thank You, it's easier than I thought :) working fine – cr4ces Apr 29 '22 at 11:14

0 Answers0