【发布时间】:2017-12-05 14:45:06
【问题描述】:
我有两个 PS 脚本(1 个主脚本和 1 个作为模块)。
主脚本使用如下代码:
Write-Host "Press Y to continue"
Execute (ConstructSshSessions)
其中Execute 是一个函数,它询问问题以继续并执行函数ConstructSshSessions 中的脚本。如果用户没有输入Y,则主脚本会跳过函数ConstructSshSessions。
模块使用如下代码:
Function Execute($function)
{
$response = read-host
Write-Host "You typed: $response"
if ($response -eq "Y")
{
$function
}
Remove-Variable response
}
当我执行代码 Excecute (ConstructSshSession) 时,它首先运行创建 SSH 会话的脚本,然后要求用户继续。所以这显然不是我的意图,但我没有看到错误。
我希望它询问用户是否可以继续,然后执行作为参数发送到函数 Execute 的脚本。
【问题讨论】:
标签: powershell parameter-passing