0

The user launchs a script called wrapper.ps1 It has

param(
  [string]$command,
  [string]$item=''
  etc
)

I then evaluate this with

switch -wildcard ($command) {
  "command1" {function1 $item;}
  "command2" {function2 $item;} 
  etc. 
 }

Then I have a function1 like:

function function1 {
   param([string] $itemname =''}
   #etc...then:
   $summary = @{blah1 = $blah1; blah2= $blah2; blah3= $blah3; }
   return $summary

$blah# are simple strings. The question is how can I pipeline into function1 via wrapper.ps1? I'd like to call this script like this:

wrapper.ps1 command1 filename |ft blah1,blah3

rismoney
  • 531
  • 6
  • 21

1 Answers1

2

You choose to return a hashtable so you can exploit it from the pipeline

wrapper.ps1  "command1" "item" | select -ExpandProperty values

or

wrapper.ps1 "command1" "item" | % {foreach ($hash in $_.keys){write-host "the key is $hash the value is $($_[$hash])"}}
JPBlanc
  • 70,406
  • 17
  • 130
  • 175
  • everything works when I call the ps1 file directly-apparently, and the information you provided is great! The problem I am actually experiencing is I am calling the wrapper.ps1 from inside a .cmd file like: powershell.exe -command wrapper.ps1 %* and I think this breaks the piping capability since %* may not know what to do with the pipe...hrmmmph – rismoney May 24 '12 at 11:49