I am currently using a batch file to silently install multiple software, after the fresh installation of Windows. I simply double-click the batch file and everything is installed silently without any prompts.
Using PowerShell, I want to create a simple GUI showing the list of software with check-boxes next to them, so someone can select the software the want to install, click the “Install” button and their selections will be installed.
I have some PowerShell experience with scripting and automation, but nothing with creating a GUI.
If I can have an example of how to do this, it would get me started and I could create my list.
I have this, but I’m doing something wrong because when I run the script, the installation starts immediately. Whereas I should select, click ok, and the the installation should start.
When do you want to invoke the installation?
Is it at the checkbox checked state or while clicking the OK button?
If it is checked state, below code should go within the checked state change event of the checkbox and it will be a good idea if you disable the checkbox once checked. Otherwise, your end users may trigger multiple instances of installations.
[PRE]
If ($checkbox1.Checked = $true) { C:\software\7z1900-x64.exe }
[/PRE]
If it is while clicking the OK button then it should go within the click event of OK button.
The idea is that you select all the software you want to install, and then you click OK. At which point the software you selected, start installing one by one.
Add a click event to the OK button, then check the checked status of each checkbox. If the checked status is true, then use the start-process cmdlet with -wait switch. This will trigger the installation one at a time.
Your GUI will go freeze until everything finishes.
[PRE]
$OKButton.Add_Click({
If ($checkbox1.Checked = $true)
{
Start-Process -FilePath ‘C:\software\7z1900-x64.exe’ -Wait
Actually the click event script block waits until evrything finishes then release the control back to form, so yor GUI goes to unresponsive state.
One of my scenario, I gathered all the commands and it’s arguments to a script block, in your case the exe files and may be their switces. Then I started a new powershell process within the click event and passed that script block as an argument, so another powershell window opened and task started in that window. Then closes the GUI. The new window will automatically closes once done with all of my activities.
Also you could start that script block as a JOB within powrshell so that it runs in the background.