Hi, I fixed the problem now but I'm just curious why it hapend. So, Tl;Dr, my code threw this error:
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
At C:\Important\programming\powershell\JLang\varWork.ps1:13 char:5
+ $variables += [PSCustomObject]@{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
in this function
function createVar {
param(
$name,
$value,
$variables
)
#$name
#$value
$variables.GetType().Name
$variables += [PSCustomObject]@{
Name = $name
Value = $value
Type = $value.GetType().Name
}
return $variables
}
and didn't work as intended when I didn't parsed $variables, but when I added the line $variables.GetType().Name it fixed itself, it didn't threw this error and worked fine, how could just this fix it? It seems so weird because that line should just do side effect and side effects shouldn't change code behaviour? Am I missing something here? BTW: I'm pretty new to PowerShell but not programming