SOLVED

PowerShell: GUI programming - Combo boxes

%3CLINGO-SUB%20id%3D%22lingo-sub-657921%22%20slang%3D%22en-US%22%3EPowerShell%3A%20GUI%20programming%20-%20Combo%20boxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-657921%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20All%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ei%20am%20trying%20to%20build%20a%20simple%20GUI%20where%20users%20selects%20one%20of%20the%20two%20options%20from%20a%20drop%20down%20menu%20and%20click%20launch%20button.%20I%20have%20two%20PowerShell%20scripts.%20Scripts%201%20and%20Script%202.%20Based%20on%20the%20option%20select%20by%20the%20user%20from%20the%20drop%20down%20menu%2C%20it%20launch%20runs%20script%201%20or%20script%202%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20576px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F116569i67B199819F1B26F9%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22IM8.JPG%22%20title%3D%22IM8.JPG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Ehow%20to%20connect%20my%20two%20PowerShell%20scripts%20to%20these%20two%20drop%20down%20menu%20options%3F%3C%2FP%3E%3CP%3Eany%20tutorial%20links%20will%20be%20greatly%20appreciated.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance%20everyone.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-657921%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ECombo%20Box%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-658252%22%20slang%3D%22en-US%22%3ERe%3A%20PowerShell%3A%20GUI%20programming%20-%20Combo%20boxes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-658252%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F318231%22%20target%3D%22_blank%22%3E%40ShehzadUIT%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20Launch%20button%20click%2C%20you%20have%20to%20get%20selected%20option%20and%20based%20on%20this%20option%2C%20you%20have%20to%20load%20your%20script%20file%20(assumed%20.ps1%20file)%20and%20call%20the%20relevant%20function.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24scriptOption%20%3D%20%23get%20selected%20dropdown%20item%20text%3CBR%20%2F%3E%3CBR%20%2F%3Eif(%24scriptOption%20-eq%20%22Script1%22)%20%7B%3CBR%20%2F%3E%23Initialize%20script1%3CBR%20%2F%3E.%20C%3A%5CScripts%5CScript1.ps1%3CBR%20%2F%3E%23Call%20function%20in%20script1%3CBR%20%2F%3ETestFunction%3CBR%20%2F%3E%7D%20else%20%7B%3CBR%20%2F%3E%23Initialize%20script2%3CBR%20%2F%3E.%20C%3A%5CScripts%5CScript2.ps1%3CBR%20%2F%3E%23Call%20function%20in%20script2%3CBR%20%2F%3ETestFunction%3CBR%20%2F%3E%7D%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Highlighted
Contributor

Hi All,

 

i am trying to build a simple GUI where users selects one of the two options from a drop down menu and click launch button. I have two PowerShell scripts. Scripts 1 and Script 2. Based on the option select by the user from the drop down menu, it launch runs script 1 or script 2:

 

IM8.JPG

how to connect my two PowerShell scripts to these two drop down menu options?

any tutorial links will be greatly appreciated.

 

Thanks in advance everyone.

1 Reply
Highlighted
Solution

@ShehzadUIT 

 

In Launch button click, you have to get selected option and based on this option, you have to load your script file (assumed .ps1 file) and call the relevant function.

 

$scriptOption = #get selected dropdown item text

if($scriptOption -eq "Script1") {
#Initialize script1
. C:\Scripts\Script1.ps1
#Call function in script1
TestFunction
} else {
#Initialize script2
. C:\Scripts\Script2.ps1
#Call function in script2
TestFunction
}