Search code examples
powershellpowershell-2.0powershell-3.0powershell-4.0

Combo Box in powershell... how to process based on drop down selection


Below is the code snippet, wen computer name is selected from the drop down and entered it should produce result in text file as shown below. How ever combo box selection is showing error.

`$buttonEnter_Click= {

if ($combobox1.SelectedItem.ToString == "Computer name")
{
    $path = "$([Environment]::GetFolderPath("Desktop"))\information.txt";
    gcim Win32_OperatingSystem | fL * | fl > $path; notepad $path;
}

}`I have a combo box based on drop down selection it should give output in text file. Computer name, computer description should come in text file once enter button is clicked


Solution

  • try somethng like this

     $handler_button1_Click=
     {
        if ($combobox1.Text -eq "Computer name")
        {
            $form1.Text = $combobox1.Text;
            $path = "$([Environment]::GetFolderPath("Desktop"))\information.txt";
            gcim Win32_OperatingSystem | fL * | fl > $path; notepad $path;
    
        }
    
     }
    
     $buttonEnter.add_Click($handler_button1_Click)
     $form1.Controls.Add($buttonEnter)