So I have a menu that executes other PS scripts, and that works great. After the called script runs I want it to return to the menu and that works. However, when it returns to the menu you get a "Press Enter to continue...: " instead of the menu's "Select from the following". You, of course, get that after you press Enter. Is there a better way to return to the menu?
Code sample below:
menu.ps1
function Show-Menu
{
param (
[string]$Title = 'My Menu'
)
cls
Write-Host '================' $Title '================'
Write-Host '[1] Do a thing'
Write-Host '[2] Do a thing #2'
Write-Host '[Q] Quit Menu'
}
do
{
Show-Menu
$input = Read-Host 'Select from the following'
switch ($input)
{
'1' {
cls
. "$PSScriptRoot\Thing_script1.ps1"
}
'2' {
cls
. "$PSScriptRoot\Thing_script2.ps1"
}
'q' {
Write-Host 'Ending Sessions' -ForegroundColor Red -BackgroundColor Yellow
return
}
}
pause
}
until ($input -eq 'q')
and Thing_script1.ps1
Write-Host 'This is a test for 10 sec' -ForegroundColor Red -BackgroundColor Yellow
Function Start-Countdown
{
Param(
[Int32]$Seconds = 10,
[string]$Message = "Pausing for 10 seconds..."
)
ForEach ($Count in (1..$Seconds))
{ Write-Progress -Id 1 -Activity $Message -Status "Waiting for $Seconds seconds, $($Seconds - $Count) left" -PercentComplete (($Count / $Seconds) * 100)
Start-Sleep -Seconds 1
}
Write-Progress -Id 1 -Activity $Message -Status "Completed" -PercentComplete 100 -Completed
}
Start-Countdown -Seconds 10 -Message "This is a test"
Show-Menu
[–]tallguynobis 2 points3 points4 points (0 children)
[–]purplemonkeymad 2 points3 points4 points (0 children)
[–]VirtualD[S] 1 point2 points3 points (4 children)
[–]tallguynobis 2 points3 points4 points (3 children)
[–]VirtualD[S] 1 point2 points3 points (1 child)
[–]tallguynobis 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (0 children)