I have a PowerShell script with a WPF GUI that allows the users to enter values and choose from drop-down lists. It works great, but some users want to bypass it and run the script manually (enter their own values directly into the script).
Right now the structure is:
#A bunch of XML and PowerShell that generates the GUI
$WPFbutton.Add_Click({
#Variables that get populated by the GUI
#The rest of the script
})
I want to add something like:
$UseGUI = $true
at the top of the script that they can change to false, which will cause the script to ignore the XML and button click line.
I was thinking I could surround the XML stuff in an if statement based on $UseGUI
but that doesn't help with the button click part.
One thing I know would work is copy and pasting the entire script to another if statement based on $UseGUI
. The issue there is it would double the script size, and it's already 2000 lines.