用于打开新终端窗口的Powershell功能范围

时间:2017-09-11 18:52:24

标签: powershell

我使用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
  }
}      

有没有办法让这些参数可用?

1 个答案:

答案 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
}