Page 1 of 1
PowerShell Script using array as parameter - How?
Posted: 28.09.2023, 12:00
by fcx64
Hi. How do I get an array to my PowerShell script? I tried a lot and this command line is the closest I get. It works for 1 selected item.
Multiple Items don't work.
I know that PowerShell wants an array as
@() but this didn't work either.
Output of
%Dlg%
Code: Select all
-noe -nol -file "F:\-Test.ps1" -Babbel ("F:\TEMP\File 001.txt","F:\TEMP\File 002.txt","F:\TEMP\File 003.txt","F:\TEMP\File 004.txt","F:\TEMP\File 005.txt")
Thank you.

Re: PowerShell Script using array as parameter - How?
Posted: 28.09.2023, 12:06
by fcx64
I forgot the script, sorry.
Code: Select all
Param (
[Parameter(Mandatory = $True)]
[System.String [] ] $Babbel
)
foreach ($b in $Babbel) {
Write-Host "$b`n"
}
Read-Host
Re: PowerShell Script using array as parameter - How?
Posted: 13.10.2023, 19:09
by Forez
Perhaps you have run into similar kind of limitation / bug that I have:
https://freecommander.com/forum/viewtopic.php?p=41735?
Re: PowerShell Script using array as parameter - How?
Posted: 16.10.2023, 23:44
by TK87
Hi there.
fcx64 wrote: 28.09.2023, 12:00
How do I get an array to my PowerShell script? I tried a lot and this command line is the closest I get. It works for 1 selected item.
Multiple Items don't work.
I know that PowerShell wants an array as
@() but this didn't work either.
Your problem actually has nothing to do with FreeCommander. Windows has the restriction that all programs are executed as the CMD would call them.
You cannot pass an array as a single argument, otherwise it would always be interpreted as a single contiguous string. One possibility would be to split this string inside the script.
The better solution would be to use the advanced parameter "
ValueFromRemainingArguments".
Code: Select all
Param (
[Parameter(Mandatory, ValueFromRemainingArguments)]
[System.String[]] $Babbel
)
foreach ($b in $Babbel) {
Write-Host "$b`n"
}
See
about_Functions_Advanced_Parameters
For example, if you use
%ActivSel% in FreeCommander, you can select multiple files and run the script
Regards, Thomas