【发布时间】:2019-08-06 14:38:59
【问题描述】:
我使用的 PowerShell 版本是 5.0。我有一种情况,我需要使用一个函数并在 switch 语句中调用它。我的工作涉及做几项操作。
简而言之,我的场景是switch语句的输入是两个A和B。我必须在switch“conditionB”中调用在switch“condition A”中声明的函数,我的意思是执行同一组操作.
例外:
installsw 未被识别为 cmdlet、函数、脚本文件的名称, 或可运行的程序。检查名字的拼写, CategoryInfo : ObjectNotFound: (regupgrade:String) [], CommandNotFoundException fullyQualifiedErrorId:CommandNotFoundException$condi = Read-Host -Prompt "Enter the input"
switch ($condi) {
A {
function installsw() {
Write-Host "install necessary sw"
install some s/w using "Start-Process" Command
}
installsw
}
B {
Write-Host "s/w upgrade"
installsw
$logs = Copy-Item -Path"D:/var" -Destination "D:/Temp"
}
}
【问题讨论】:
标签: function switch-statement powershell-5.0