Suppose you define map_ps
in map.ps1
:
function map_ps{
[CmdletBinding()]
param([parameter(ValueFromPipeline=$true)]$InputObject,$sb,$ArgumentList)
process{&$sb $ArgumentList}
}
Suppose you also define another function map_psm
with identical implementation in a well-formed module called map.psm1
:
function map_psm{
[CmdletBinding()]
param([parameter(ValueFromPipeline=$true)]$InputObject,$sb,$ArgumentList)
process{&$sb $ArgumentList}
}
Calling each function with identical parameters does not yield the same result:
PS C:\> 1 | map_ps -sb {"DollarBar:$_, Arg:$($args[0])"} -ArgumentList 2
DollarBar:1, Arg:2
PS C:\> 1 | map_psm -sb {"DollarBar:$_, Arg:$($args[0])"} -ArgumentList 2
DollarBar:, Arg:2
Why is $_
empty when the function is implement in a .psm1
but it isn't when the function is implemented in a .ps1
?