I need to create a function.
First variable must be an array with an unknown number of parameters plus another variable.
My problem is that I don’t know how distinguish between them.
I post an example:
function conc-str {
param([string[]]$array,[string]$name)
foreach($item in $array) {
$str+= $item
}
write-host $str
}
conc-str(@("aa","bb","cc"),"dd")
The result of this function is
aa bb ccdd
but as you can see I loop array elements and concatenate them. I thought to get just
aa bb cc
Where is my mistake?
The way you call it is:
You don’t use “,” as a parameter seperator in PowerShell. It is just a space. The moment you put a “,” it becomes a single parameter.