我使用powershell功能打开一个新的终端窗口。我希望能够在此窗口中运行一个可以访问该功能参数的脚本。但是在start powershell
块内,函数的参数不可用:
function startChalk([string] $thing) {
echo "thing is $thing" # this works - here we have access to $thing
start powershell {
echo "now it's $thing" # this fails - here we have no access to $thing
}
}
有没有办法让这些参数可用?
答案 0 :(得分:0)
使用(正确转义的)可扩展字符串("like $this"
)作为参数而不是scriptblock文字:
function startChalk([string] $thing) {
echo "thing is $thing" # this works - here we have access to $thing
powershell -Command "echo 'now it''s $thing'" # this fails - here we have no access to $thing
}