Help with GUI
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- WSUsoftware
- Posts: 30
- Last visit: Thu Feb 17, 2022 2:52 pm
Help with GUI
I tried searching but all the examples I found fell just short of answering my questions. I am trying to make a Powershell Form (.psf) that contains a "CheckedListBox". Each item in the CheckedListBox corresponds to a program I want to install. I want to be able to select multiple Boxes and then click the "OK" button to make them run. I successfully created a Powershell Script (.ps1) that does this, but to manually type in all the buttons, checkboxes, etc...would make a script about 4,000 lines long. Obviously there is an easier way to do this by making a GUI, but I am not sure how to fill out the "script" portion in the Powershell Form to accomplish this. The first picture below is some of the code from the script . The second and third pictures show the form I have designed in powershell studio as well as the script that I am having trouble understanding. To make the powershell form I am using Powershell Studio 2015.
- Attachments
-
- Part one of my manually typed form code
- Script Part 1.PNG (42.96 KiB) Viewed 3911 times
-
- Code autogenerated by doubleclicking the objects
- Form 2.PNG (63.54 KiB) Viewed 3911 times
-
- The form I created using the GUI tools
- Form 1.PNG (26.37 KiB) Viewed 3911 times
Re: Help with GUI
You should note that a checked listbox is loaded the same way as a listbox.
$checkelistbox1.Items.AddRange(@( 'one','two','three','four'))
This will load a checked listbox with those items.
$checkelistbox1.Items.AddRange(@( 'one','two','three','four'))
This will load a checked listbox with those items.
- dan.potter
- Posts: 709
- Last visit: Wed Nov 14, 2018 11:39 am
Re: Help with GUI
You're going to need a switch to associate the checkboxes with the appropriate program to run as well as a foreach statement to go through each checkbox and run if checked.
Re: Help with GUI
No - not really. Just store the program name in the listbox and retrieve it as you process the checks. Remember that listboxes can be tied to objects or datatables and display any field as well as set the default check state based on a field. We can then retrieve the whole row and any scripts or programs it contains.dan.potter wrote:You're going to need a switch to associate the checkboxes with the appropriate program to run as well as a foreach statement to go through each checkbox and run if checked.
No need for switch statements in Forms if you use the forms tools. Think of a listbox as a big, visual switch statement,.
- dan.potter
- Posts: 709
- Last visit: Wed Nov 14, 2018 11:39 am
Re: Help with GUI
I was thinking associate program name to msi which I wouldn't put in the listbox. I think he's using the listbox for output.
- dan.potter
- Posts: 709
- Last visit: Wed Nov 14, 2018 11:39 am
Re: Help with GUI
Using your demo this is what I meant.
- $buttonOK_Click = {
- foreach ($program in $checkedlistbox1.CheckedItems) {
- switch ($program) {
- chrome{ Write-Host 'chrome selected'; $installfile = 'chrome.msi'}
- 'powershell studio'{ Write-Host 'ps studio selected'; $installfile = 'psstudio.exe'}
- }
- Write-Host "installing $installfile"
- }
- }
Re: Help with GUI
An MSI is an executable. It does not need to find a program. No installer needs a program. Just place the name of the installer file and all options in the checkedlistbox.dan.potter wrote:I was thinking associate program name to msi which I wouldn't put in the listbox. I think he's using the listbox for output.
- dan.potter
- Posts: 709
- Last visit: Wed Nov 14, 2018 11:39 am