As for this…
I could not find a script anywhere on the net to create a pop box, with drop down menus
… where did you look. As there is a module for this type of thing in the MS PowerSellGallery.
Find-Module -Name 'AnyBox' | Format-Table -AutoSize
Version Name Repository Description
------- ---- ---------- -----------
0.3.3 AnyBox PSGallery Designed to facilitate script input/output with an easily customizable WPF window
The authors doc on the tool, specifically the drop down part.
$prompt = New-AnyBoxPrompt -Name 'fav_sport' `
-Message 'What is your favorite sport?' `
-ValidateSet @('Basketball', 'Football', 'Baseball', 'Soccer', 'Hockey', 'Other') `
-DefaultValue 'Baseball'
Show-AnyBox -Icon 'Question' -Prompt $prompt -Buttons 'OK'
This uses also the more modern, support WPF (Windows Presentations Foundation) vs WF (Windows Forms) that your code is using.
Prompts
https://www.donaldmellenbruch.com/doc/anybox/prompts
Secondly, rule of thumb, when you get into a space of If/then exceeds say 3 or more, it’s time to look at using a switch statement, for ease of readability, maintenance, etc. You also almost never read Write-Host, unless you are using foreground or background colors or other custom formatting needs. If you are looking to just send to the screen, Write-Output is the default, so, you don’t need Write-* at all.
Example:
function Return-DropDown
{
$script:Choice1 = $DropDownType.SelectedItem.ToString()
switch ($Choice1.Text)
{
'DESKTOP' { $Desktop | Out-Default}
'LAPTOP' { $LAPTOP | Out-Default }
default { 'The choice could not be determined.' }
}
}
function Return-DropDown
{
$script:Choice2 = $DropDownRegion.SelectedItem.ToString()
switch ($Choice2.Text)
{
'ZWELITSHA' { $Site00 | Out-Default }
'BUTTERWORTH' { $Site02 | Out-Default }
'BIZANA' { $Site03 | Out-Default }
'COFIMVABA' { $Site04 | Out-Default }
'CRADOCK' { $Site05 | Out-Default }
'EAST LONDON' { $Site06 | Out-Default }
'FORT BEAUFORT' { $Site07 | Out-Default }
'GRAHAMS TOWN' { $Site08 | Out-Default }
'GRAAF REINET' { $Site09 | Out-Default }
'IDUTYWA' { $Site10 | Out-Default }
'JJ SERFONTEIN' { $Site11 | Out-Default }
'KING WILLIAMSTOWN' { $Site12 | Out-Default }
'LIBODE' { $Site13 | Out-Default }
'LUSIKISIKI' { $Site14 | Out-Default }
'MT AYLIFF' { $Site18 | Out-Default }
'MT FLETCHER' { $Site15 | Out-Default }
'MT FRERE' { $Site16 | Out-Default }
'MALUTHI' { $Site17 | Out-Default }
'MTHATHA' { $Site19 | Out-Default }
'NGCOBO' { $Site20 | Out-Default }
'PORT ELIZABETH' { $Site21 | Out-Default }
'QUMBU' { $Site22 | Out-Default }
'QUEENSTOWN' { $Site23 | Out-Default }
'STERKSPRUIT' { $Site24 | Out-Default }
'UITENHAGE' { $Site25 | Out-Default }
'LADY FRERE' { $Site28 | Out-Default }
default { 'The choice could not be determined.' }
}
}
And as a rule, unless you need to expand variables, use single quotes for strings. If you only have one variable, that you are using / outputting, it does not really needs double quotes either. It does not hurt having them there, but just saying.
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules
https://www.sconstantinou.com/powershell-quotes
https://www.red-gate.com/simple-talk/sysadmin/powershell/when-to-quote-in-powershell
https://www.itprotoday.com/powershell/single-quotes-vs-double-quotes-powershell-whats-difference
https://trevorsullivan.net/2016/07/20/powershell-quoting
https://blogs.msdn.microsoft.com/koryt/2018/03/01/powershell-for-programmers-strings-quotes-and-quirks
As for…
I am new to this and would appreciate some help.
You can start with clicking and using the resources on this site, by clicking the ‘Free Resources’ link in the left navigation pane as well as these resource threads.
https://www.reddit.com/r/PowerShell/comments/aw8cvk/course_to_increase_knowledge_of_windows/ehl4ixm/?context=3
https://www.reddit.com/r/PowerShell/comments/ausa1n/beginner_help/ehawij5/?context=3
https://www.reddit.com/r/PowerShell/comments/ar6cvt/powershell_in_depth_second_edition/egmlpom/?context=3
https://ww.reddit.com/r/PowerShell/comments/afqmmw/i_want_to_help_my_husband_advance_his_powershell/ee3k6p6/?context=3
And this…
https://blogs.msmvps.com/richardsiddaway/2019/02/21/the-source-of-powershell-cmdlets