I have an array object variable as [ref] $InsertColHeadName = @()
in a function and then call another function with param ([ref] $InsertColHeadName)
. In the called function I then tried refering to my parameter set in param ([ref] $InsertColHeadName) += expression
. The expression returns a string. I placed a breakpoint in the line and tried forcing a string with single quotes eg.: ([ref] $InsertColHeadName) += 'xyz';
.
I tried googling around but can't seem to find a suitable solution.
I am getting the following error:
Method invocation failed because [System.Management.Automation.PSReference`1 [[System.Management.Automation.PSReference`1 [[System.Management.Automation.PSReference`1 [[System.Object[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]] does not contain a method named 'op_Addition'. At line:1 char:1 + ([ref] $InsertColHeadName) += 'DepartmentNo'; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound
[ref]$arr = @()
instead of$arr = @()
in the first place? – Ansgar Wiechers