question

SJB-0807 avatar image
0 Votes"
SJB-0807 asked MotoX80 answered

$ComboBox add a hidden ID

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.Items.Add($Customer.Name);
    
 }
 $ComboBox.Location  = New-Object System.Drawing.Point(80,10)
 $main_form.Controls.Add($ComboBox)
    
 $Label2 = New-Object System.Windows.Forms.Label
    
 $Label2.Text = “Users”
 $Label2.Location  = New-Object System.Drawing.Point(10,60)
 $Label2.AutoSize = $true
 $main_form.Controls.Add($Label2)
    
    
 $Label3 = New-Object System.Windows.Forms.Label
 $Label3.Text = “”
 $Label3.Location  = New-Object System.Drawing.Point(10,90)
 $Label3.AutoSize = $true
 $main_form.Controls.Add($Label3)
    
 $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”
 $main_form.Controls.Add($Button)
    
 $Button.Add_Click(
 {
 $Label3.Text = $ComboBox.selectedItem
 )
    
 $main_form.ShowDialog()
windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MotoX80 avatar image
0 Votes"
MotoX80 answered

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

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


125666-capture.jpg


https://devblogs.microsoft.com/scripting/powertip-get-row-from-csv-file-based-on-value/



capture.jpg (49.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.