$ComboBox add a hidden ID

SJB 1 Reputation point

I am making a GUI for some partner center powershell commands. So far I have it losting all our customers names in a combobox but I then need to get the CustomerID for the next stage but all I can return is their name.

I would like to add a property for the ID and then be able to retrieve it when a customer is selected. My code is below but I can't find out how to add $Customer.CustomerID to the item

$ComboBox = New-Object System.Windows.Forms.ComboBox
$ComboBox.Width = 300
$Customers = Get-PartnerCustomer
Foreach ($Customer in $Customers)

$ComboBox.Location  = New-Object System.Drawing.Point(80,10)

$Label2 = New-Object System.Windows.Forms.Label

$Label2.Text = “Users”
$Label2.Location  = New-Object System.Drawing.Point(10,60)
$Label2.AutoSize = $true

$Label3 = New-Object System.Windows.Forms.Label
$Label3.Text = “”
$Label3.Location  = New-Object System.Drawing.Point(10,90)
$Label3.AutoSize = $true

$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Size(400,10)
$Button.Size = New-Object System.Drawing.Size(120,23)
$Button.Text = “Get Users”

$Label3.Text = $ComboBox.selectedItem

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,407 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 32,246 Reputation points

    How are you building the $Customers variable? A csv? Can you just do a match?

    $Customers = import-csv c:\temp\foo.csv  
    "Now do a Lookup"  
    $LookFor = "YYYY"  
    $SelectedCust = $Customers -match $LookFor   
    "Or this way"  
    $LookFor = "XXXX"  
    $SelectedCust = $Customers.Where({$PSItem.Name -eq $LookFor})  



    0 comments No comments