I have several PS1s with functions in them in the format "Invoke-T1234", "Invoke-T1235", etc. I'd like to create a function in a PS Module that allows the user to call one of these PS1s through an argument, e.g. "Invoke-Script -Script T1234" and it then runs "Invoke-T1234". Is it possible to pass in a variable to the function that calls the scripts so I don't have to create several "If" clauses?
E.g.
function Invoke-Script {
param (
[Parameter(Mandatory = $false)]
[string]$Script= ""
)
If ($Script){
Invoke-$Script
}
Obviously this isn't working, as PowerShell is interpreting $Script literally instead of the value.
I know I can do
If ($Script -eq T1234){
Invoke-T1234}
But there are many PS1s, so I'd like to do this in the least amount of code possible.