Then i have a "memberof" list comming from a computer object.
When rendering the listbox, i'd like to select the groups that match.
I've build myself an example.
- # build list with groups into listbox1
- $groups = get-adgroup -LDAPFilter "(name=gc08*)" | Select name
- foreach ($g in $groups){
- $listbox1.Items.Add($g.Name)
- }
- #mock memberof groups
- $searchstrings = @(
- "*informatica*",
- "*HR*",
- "*Marketing*"
- )
- #Pre-select current groups
- foreach ($searchstring in $searchstrings){
- for ($i = 0; $i -lt $listbox1.Items.Count; $i++) {
- $p = $listBox1.Items[$i].ToString()
- if ($p -like $searchstring) {
- Write-Host "Match found with filter $($searchstring):" $listBox1.Items[$i]
- $listBox1.SetSelected($i, $true);
- }
- }
- }
I have set the SelectionMode to MultiExtended but that made no difference.
Anyone can help me out?