我有一个菜单驱动的powershell脚本做了一些事情。
菜单开关包含..
[cmdletbinding()]
param (
[Parameter(Mandatory = $false, Position = 0)]
[ValidateSet('Interactive', 'Scheduler')]
[string]$Operation = "Interactive"
)
function mytest {
Write-Host "this is a test"
}}
Switch ($Operation)
{
'Interactive' { . (Join-Path $ScriptPath main.ps1) }
'Scheduler' { . (Join-Path $ScriptPath scheduler.ps1) }
'Shell' { . (Join-Path $ScriptPath shell.ps1) }
}
我已在此脚本中定义了许多函数,我希望能够使用"myscript.ps1 -Operation Shell"
调用脚本,该脚本会生成一个新的PowerShell控制台,我可以在其中手动输入命令并且还可以访问到执行主脚本期间设置的已定义函数。
这与在Windows中手动运行powershell控制台没有什么不同,除非通过设置一堆函数和参数的脚本调用。