I have PS scrip that presents two item menu. I have common section that should apply to either selection. But I can not get it working. The only way it to add all from that section to each of the two function sections (but that makes script bigger for no reason) Code: # define a task list with the messages to display and the functions to invoke: $taskList = @( [PSCustomObject]@{Message = 'File Selection'; Task = { FileSelect }} [PSCustomObject]@{Message = 'Folder Selection'; Task = { FolderSelect }} ) # define the functions: function FolderSelect() { Write-Host "Folder Selection" function FileSelect() { Write-Host "File Selection" # let the user pick a task: Write-Host -ForegroundColor Yellow "Choose a task:" $taskList | foreach -Begin { $i = 1;} -Process { Write-Host -ForegroundColor Yellow ('{0}. {1}' -f ($i++), $_.Message) } do { $value = Read-Host 'Choose a number from the task list' } while($value -match '\D+' -or $value -le 0 -or $value -gt $taskList.Count) # invoke the task: & $taskList[$value-1].Task Need a common section to be run after either selection Help appreciated for pointing what I am missing
Define "Common" section as function ProcessSelection() and just called it from within each other existing function So batch :COMMON is really PS function