用户启动一个名为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 文件名 |ft blah1,blah3
选择返回哈希表,以便可以从管道中利用它
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])"}}