用户启动一个名为wrapper.ps1的脚本 它有
param(
[string]$command,
[string]$item=''
etc
)
然后我用
评估这个switch -wildcard ($command) {
"command1" {function1 $item;}
"command2" {function2 $item;}
etc.
}
然后我有一个函数1:
function function1 {
param([string] $itemname =''}
#etc...then:
$summary = @{blah1 = $blah1; blah2= $blah2; blah3= $blah3; }
return $summary
$ blah#是简单的字符串。 问题是如何通过wrapper.ps1管道进入function1? 我想像这样调用这个脚本:
wrapper.ps1 command1 filename | ft blah1,blah3
答案 0 :(得分:2)
您选择返回哈希表,以便可以从管道中利用它
wrapper.ps1 "command1" "item" | select -ExpandProperty values
或
wrapper.ps1 "command1" "item" | % {foreach ($hash in $_.keys){write-host "the key is $hash the value is $($_[$hash])"}}