如何分叉新的PowerShell窗口并传入函数?

时间:2018-01-22 18:34:24

标签: powershell

我有一个菜单驱动的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控制台没有什么不同,除非通过设置一堆函数和参数的脚本调用。

0 个答案:

没有答案