I noticed that you are using a "workflow" in your example parameter [ref]. For simplicity, let's call it a “function” and return to the “workflow” later.
Three things need to be changed in the code:
- When passing the [ref] parameter to a function, enclose the parameter in parentheses
() . - When using the [ref] parameter inside a function, refer to $ variable.value
- Remove the type [string] from the definition of your parameter. It can be [string] or [link], but not both at the same time.
Here is the code that works:
function Test { Param([Parameter(Mandatory=$true)][ref]$someString) write-verbose $someString.value -Verbose $someString.value = "this is the new string" } cls $someString = "hi" Test -someString ([ref]$someString) write-host $someString
As for the "workflows." They are very limited, read PowerShell Workflows: Limitations . In particular, you cannot call a method on an object in a workflow. This will break the line:
$someString.value = "this is the new string"
I don’t think that using the [ref] parameters in the workflow is appropriate due to the limitations of the workflow.
Jan Chrbolka
source share