GUI WPF Search Function within

hello there powershell brothers and sisters,

I’m playing a bit with WMF and trying to figure out how to create a search field or search function in a list.

For example, I have a list box containing all expired accounts, instead of scrolling I want to enter the name. But I have no idea how to define such an object.

Does anyone know a good book that covers everything around Powershell GUI.


Kind regards,

Best i can point you to would be Learn Powershell toolmaking in a month of lunches.


its not going to answer all of your questions, but the big thing to learn, is all of the elements in your gui, are just objects, you interact with them in the same way you deal with any other object in powershell.

Thanks for the tip David.

I will look whats been covered.


function keuze{

[string]$results = $ExpiredAccountCombo.Text.ToString()


The selected within the combox value gets in $ExpiredAccountCombo.Text.ToString() but [string]$results =ExpiredAccountCombo.Text.ToString() is not putting the value in the variable…

What am I doing wrong ?






------code —

Add-Type -AssemblyName System.Windows.Forms

$Form = New-Object system.Windows.Forms.Form
$Form.ClientSize = ‘890,722’
$Form.text = “Form”
$Form.TopMost = $false

$ExpiredAccounts = New-Object system.Windows.Forms.Label
$ExpiredAccounts.text = “Expired Accounts:”
$ExpiredAccounts.BackColor = “#b8e986
$ExpiredAccounts.AutoSize = $true
$ExpiredAccounts.width = 40
$ExpiredAccounts.height = 10
$ExpiredAccounts.location = New-Object System.Drawing.Point(14,8)
$ExpiredAccounts.Font = ‘Microsoft Sans Serif,10,style=Bold,Underline’

$ExpiredAccountCombo = New-Object system.Windows.Forms.ComboBox
$ExpiredAccountCombo.text = “Expired Accounts”
$ExpiredAccountCombo.width = 255
$ExpiredAccountCombo.height = 20
$ExpiredAccountCombo.location = New-Object System.Drawing.Point(15,52)
$ExpiredAccountCombo.Font = ‘Microsoft Sans Serif,10’


$ExpiredAccountCombo.Add_Click({ Keuze })

foreach ($item in $users )

function keuze{

[string]$results = $ExpiredAccountCombo.Text.ToString()


[void] $Form.ShowDialog()

Have you tried putting your function at the top of the code? It should be one of the first things that initializes when the code runs. I’ve been working with WPF quite a bit recently and have been tripped up quite a bit with making sure I was calling my variables and functions in the right order or else they didn’t work as expected.

There are many examples of creating forms with Powershell. There are tools and entire websites dedicated to it. When I want to build something like this, I find examples close to what I’m trying to accomplish to use as a framework and make changes to fit the requirements. It also looks like you are trying to get information in a GUI and then exit the GUI to do something with that information. Typically, you would execute processes on selections with button clicks (or other events) rather than trying to use the GUI to gather information and exit to process it.

Try this


function keuze{
    $script:results = $ExpiredAccountCombo.Text.ToString()
    write-host $script:results

[void] $Form.ShowDialog()
write-host "---------------"
write-host $script:results