
function main {
$options = @('option1', 'option2', 'option3')
CLS; $n = 1
$options | foreach { "[{0}] {1}" -f $n, $_; $n++ }
choice /c 123 /m "Choose:"
"opt$lastexitcode"
pause; main
}
function opt1 { "this is option one" }
function opt2 { "this is option two" }
function opt3 { "this is option three" }
main
가능하다면 함수 이름을 입력하지 않고 직접 다른 함수를 호출하세요.만약에또는스위치성명?
답변1
아마도 여기에서 다음을 사용할 수 있습니다. 호출 표현식 명령.
기사에는 다음 예가 포함되어 있습니다.
$Command = "Get-Process"
Invoke-Expression $Command
다음 문서의 경고에 유의하세요(귀하의 사례와 관련이 없을 수도 있음).
유해한 것으로 간주되는 호출 표현식.