Hi there,
I need to write a script in which I need to define different functions. In addition, the script must have a menu in which to choose which function to perform. I wrote the following script:
# Main menu, allowing user selection
function Show-Menu
{
param (
[string]$Title = 'Choose Which to Start'
)
cls
Write-Host "================ $Title ================"
Write-Host "1: Press '1' to Stop LAGOServvices"
Write-Host "2: Press '2' to Start LAGOServvices"
Write-Host "3: Press '3' to Clean Temp-, Logs-, LocalhostFolders"
Write-Host "4: Press '4' to Start to Test LAGOWebsSrvices"
Write-Host "5: Press '5' to Restart LAGOServices"
Write-Host "6: Press '6' to Update LAGOServices"
Write-Host "Q: Press 'Q' to quit."
}
#Functions go here
Function StopLAGOServvices {
}
Function StartLAGOServices {
}
Function CleanTempfolder {
}
Function TestWebservices {
}
Function RestartLAGOServices {
}
Function UpdateLAGOServices {
}
#Main menu loop
do
{
Show-Menu
$input = Read-Host "Please make a selection"
switch ($input)
{
'1' {
cls
StopLAGOServvices
} '2' {
cls
StartLAGOServices
} '3' {
cls
CleanTempfolder
} '4' {
cls
TestWebservices
} '5' {
cls
RestartLAGOServices
} '6' {
cls
UpdateLAGOServices
} 'q' {
return
}
}
pause
}
until ($input -eq 'q')
This work and can choose option 1, 2, 3 etc. When a choose 1 is executed first function. I want to defined for example, function 5 which brings all other function togheter and execute all other. Something like this:
Function RestartLAGOServices { Function Stop LAGOServvices + Funcction Start LAGOServvices + Fuction Clean Temp-, Logs-, LocalhostFolders + Function Test LAGOWebsSrvices"}.
Can i use parameter for this purpose? For example:
$parameter = @(stop, start, restart, update)
if ($parameter -like start) { start Function StartLAGOServvices }
elseif ($parameter -like stop ) {stop Function Function StopLAGOServvices }
One more thing:
How define in menu, if i choose nothing it will be automatic continue to execute some script?
Thanks to each of you who will help me!