powershellsearchactive-directoryfuzzy-search

Fuzzy Search the Pipeline from the Active Directory in Powershell


I am trying to build a fuzzy search (run-time) through the pipeline already pulled from the Active Directory.

Originally I am trying to deploy the applications to the clients. So to make it an easier process for the Admins I am trying to make a fuzzy search through all the applications pulled from the AD in PowerShell.

I tried making a dropdown list since that allows the Admin ty type in the application name. But since the Ad Groups called from the AD have their starting text as "AP_SCCM_FBC_" I tried trimming the pipeline, but couldn't so I thought just to make that as loaded text in the search field, so that every time user doesn't have to type it and I used .AutoCompleteMode to append the text, But that doesn't give a proper search since I have to search the exact name of the application for example-"Microsoft_Power_BI" whereas I am trying "Power BI".

function Load-Combobox-Apps
{
    $appddl.Items.Clear()
    $apparray = Get-ADGroup -Filter {name -like "AP_SCCM_FBC_*"} | Select-Object Name
   
    $appddl.Text = "AP_SCCM_FBC_"
    ForEach ($Item in $apparray)
    {
        $appddl.Items.Add($item.Name)
        $appddl.AutoCompleteSource = 'listItems'
        $appddl.AutoCompleteMode = 'Append'
    }
}

Solution

  • For trimming the group names, you can use calculated properties like this example using split/join, which you can expand to replace underscores and such for your dropdown options:

    $apparray = Get-ADGroup -Filter {name -like "AP_SCCM_FBC_*"} |
      # trim off AD group name prefix:
      Select-Object Name, 
        @{Name='AppName';Expression={$_.Name -split 'AP_SCCM_FBC_' -join ''}}
    
    Name                           AppName
    ----                           -------
    AP_SCCM_FBC_Microsoft_Power_BI Microsoft_Power_BI
    AP_SCCM_FBC_Other_App          Other_App
    

    Then use the trimmed $item.AppName for trimmed names in the dropdown, and the original $item.Name when you need to reference the group in AD.


    For improving the autocomplete functionality, take a look through the answers here for options involving updating the dropdown list based on entered text: C# winforms combobox dynamic autocomplete

    (Be careful to only run Get-ADGroup once, or the search box will take too long to update)