I am trying to specify the value of the third parameter of the method, while still letting the second parameter in the method default.
I was able to piece this together to get it working, but I was hoping someone else had a better solution
$o=[PSCustomObject]@{};
Add-Member -MemberType ScriptMethod -InputObject $o -Name 'WrapText' -Value {
param($S,$Open='"',$Close)
if($Close){
"$Open$S$Close"
}else{
"$Open$S$Open"
}
}
$DefaultValues = @{};
$o.WrapText.Script.Ast.ParamBlock.Parameters | %{
$DefaultValues.($_.Name.ToString()) = $_.DefaultValue.Value
}
$o.WrapText('Some Text',$DefaultValues.'$Open','|')