Add WPF ComboBoxItem in PowerShell


I have been working on a PowerShell tool to create users in Active Directory with a GUI.
Thanks to Tobias Weltner and his ISESteroids it is now easy to work with XAML in PowerShell ISE.
For this tool I had to create couple of dropdown which will contains Sites list, Company list, Preferred Language list and Department list based on an XML config file.

Function New-ComboBoxItem {
            Mandatory = $true

            Mandatory = $true

        [Object]$Window = $Window
    foreach ($object in $Item) {
        $null = $Window.$ComboBoxName.Items.Add($object)

I used??$null variable??because the item id was returned.

Here is an example of the XAML I used to create the ComboBox, without items created – yet.

<ComboBox Name=”SitesList” Grid.Column=”1″ HorizontalAlignment=”Left” Margin=”10,208,0,0″ VerticalAlignment=”Top” Width=”153″/>

The way I use the function:

New-ComboBoxItem -ComboBoxName 'SitesList' -Item ($

And the result inside the window.

Leave a Reply

Your email address will not be published. Required fields are marked *