Home > Mobile >  How to pass an array to the arguments in Start-Process in Powershell?
How to pass an array to the arguments in Start-Process in Powershell?

Time:12-25

I am writing a script to play certain files in a player. I use Get-ChildItem to get an array of file names. Then I want to use Start-Process to play these files. However, how can I add these file names to the arguments of the player program?

I used Start-Process -FilePath "C:\Program Files\DAUM\PotPlayer\PotPlayerMini64.exe" -ArgumentList $selected_items but it seems it doesn't work and the files are not played.

Notice there are spaces in the file names.

CodePudding user response:

You can ForEach-Object:

Get-ChildItem . | ForEach-Object {Start-Process -FilePath "C:\Program Files\DAUM\PotPlayer\PotPlayerMini64.exe" -ArgumentList $_.FullName}

CodePudding user response:

Judging by the available command-line options, the following may work (I cannot personally verify):

/clipboard :Appends content(s) from clipboard into playlist and starts playback immediately.

# Copy the full names of the files of interest to the clipboard.
Set-Clipboard -Value $selected_items.FullName

# Launch the player and tell it to start playback of the files on the clipboard.
# Parameters -FilePath and -ArgumentList are positionally implied.
Start-Process 'C:\Program Files\DAUM\PotPlayer\PotPlayerMini64.exe' /clipboard

There are file-arguments-based options such as /new, /insert, and /add, but it's unclear to me whether they automatically start playback (may depend on the application's configuration).

  • Related