Powershell - use a function with an unknown number of variables and other parameters

I need to create a function. The first variable should be an array with an unknown number of parameters plus another variable. My problem is that I do not know how to distinguish between them.

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 process the elements of the array and combine them. I thought that just

 aa bb cc 

Where is my mistake?

+4
source share
1 answer

What do you call it:

 conc-str @("aa","bb","cc") "dd" 

You do not use "," as the parameter separator in PowerShell. It is just space. At that moment when you put the symbol ",", it becomes the only parameter.

+7
source

Source: https://habr.com/ru/post/1341752/


All Articles