I'm trying to create a cmdlet written in powershell that can accept each path from dir command and run a powershell function on this path. Example:
PS> dir *.ext | Convert-xyz
Here's what I tried below. Except, it only processes the first item listed by dir *.ext and then exits.
function Convert-xyz {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True)]
[string[]]$path,
[string[]]$function
)
foreach ($pathi in $path) {
Write-Host -ForegroundColor "Yellow" "`nPath: $pathi"
foreach ($funct in $function) {
write-host -ForegroundColor "Green" "Function: $funct"
switch($funct) {
"reflow" {reflow ($pathi); break}
"desquare" {desquare($pathi); break}
default {
write-host -ForegroundColor "Red" "Unknown function: $funct"
}
}
}
}
Write-Host "End"
} #function
foreachin there, something likedir *.exe | %{convert-xyz}( ). The calls should beshould bereflow $pathianddesquare $pathi, notreflow ($pathi)anddesquare ($pathi).