I had a lot of trouble today, until I've figured out, that [ref] parameters of functions with type attribute are limited to positional parameters.
Examples:
function GetMessage
{
Param ( [ref][string]$message )
if ($message) { $message.Value = 'Hello' }
}
$message = 'ERROR'
GetMessage -message ([ref]$message)
$message
This is not working, only because of variable name -message.
Change it to:
GetMessage ([ref]$message)
and it works.
But this way, you can only have one optional typed ref parameter, the last one.
As an alternative, you could remove the type attribute:
Param ( [ref]$message )
Then the named parameter would work again:
GetMessage -message ([ref]$message)
Question: Why it should be an issue to limit named ref parameters to a type ? I guess it's a bug.
$message.value.gettype()and remove[string]from the parameter. In this case, it works either way. Also: what is your use-case forref? I've yet to see a decent one in powershell