I have a large Powershell script that checks multiple variables on VMs. The script consists of about 80 different functions that are named question1, question2, question3...
At first none of the functions needed parameters, so this code worked.
$number_of_questions = 1..75
foreach($num in $number_of_questions){
Invoke-Expression question$num
}
It iterates thru every question
But now i need to add parameters for when i run the functions. And that doesn't work. And i cant find a way to get it to work with arguments
Here´s a testversion of what im trying to do.
function test1($text){
Write-host "Not argument"
Write-host $text
}
function test2($text){
Write-host "Not argument"
Write-host $text
}
function test3($text){
Write-host "Not argument"
Write-host $text
}
function test4($text){
Write-host "Not argument"
Write-host $text
}
function test5($text){
Write-host "Not argument"
Write-host $text
}
$num = 1..5
foreach($number in $num){
Invoke-Expression test$number -text "Argument"
}
Does anyone have a solution for running multiple functions with sequenced names that uses parameters.