Passing an array when running a PowerShell image

Hi,

I am experiencing something rather strange.

With this very simple example, the array I am passing as an argument seems to be considered as a string whatever quoting syntax I am using.

param(
    [string[]]$Items
)

foreach ($item in $Items) {
    Write-Host "Item: $item"
}
docker run --rm -v .:/tmp/scripts akamai/powershell pwsh -File /tmp/scripts/Test1.ps1 -Items 'a','b','c'
Item: a,b,c

But if I run the entrypoint without any argument, and then execute my script at interpreter level, everything is working as expected :

docker run -ti --rm -v .:/tmp/scripts akamai/powershell 
PowerShell 7.5.0
PS /> /tmp/scripts/Test1.ps1 -Items 'a','b','c'
Item: a
Item: b
Item: c

I have tried with various PS images (builder, version), even a self-made one and the behavior is always the same.

I encountered issues with booleans too, but I was able to solve it by using a syntax like '-Varname:true".

But this time I have no clue …

What I am missing ?

Regards

What makes you think it is a Docker issue? I’m not a powershell user, but I was interested and it looks like you just have to use the right syntax

pwsh -c "/tmp/scripts/Test1.ps1 -Items 'a','b','c'"

Whether you are doing as arguments of the docker run command or in Powershell without Docker, it should be the same.

I haven’t searched a lot about what -F does exactly, but when I search for using array syntax in arguments, I don’t see the -File option used.

Thanks for your answer.

I am not a regular user of PS, just need it for some VMware automation.

I thought there was an issue as I was not getting the same results between running a new image from the command line, and using the same options from within the image. So it could have been some parameters quoting issue or something like that, most of the Docker images I have used and built don’t need entrypoint parameters.

Your answer suggested me to have a closer look at the differences between “Command” and “File”.

It seems “File” is processing arguments literally, that’s why my previous attemps with simple string values were working perfectly fine.

But with “advanced” parameters, like booleans and arrays, it’s messy. So in this case, “Command” is mandatory.

“File” also seems to be the defaut mode, without explicit selection.

So here are some results to sum things up :

docker run -i -t --rm -v .:/tmp/scripts --workdir=/tmp/scripts akamai/powershell pwsh -Command /tmp/scripts/Test1.ps1 -Item a,b,c

System.String[]
3
Item: a
Item: b
Item: c

docker run -i -t --rm -v .:/tmp/scripts --workdir=/tmp/scripts akamai/powershell pwsh -File /tmp/scripts/Test1.ps1 -Item a,b,c

System.String[]
1
Item: a,b,c

docker run -i -t --rm -v .:/tmp/scripts --workdir=/tmp/scripts akamai/powershell pwsh /tmp/scripts/Test1.ps1 -Item a,b,c

System.String[]
1
Item: a,b,c

It was not a Docker issue, I was mistaken.

Problem solved.

Regards

I’m happy to hear it works. If you think my comment was the solution, please consider marking it as “Solution” so other users can see it is a solved topic.

I also edited your comment to format code and terminal output, just like I did it before with your first post. Please always use code blocks instead of quotes when sharing anything with special characters, otherwise your post can be unreadable and only moderators can fix it. If you use the “Markdown” format in the message compose, you can use our formatting guide: How to format your forum posts

Have a nice continued Docker journey!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.