How to supply a value to a [File] parameter using Invoke-PSUScript
I have a script that takes a file upload, and from the GUI it prompts for a file using the file browser. How can I call this from Invoke-PSUScript?
Hi Shannon,
Thank you for the question. Yes, you can supply the file from Invoke-PSUScript.
Invoke-PSUScript has no upload step of its own, but you can give the [File] parameter an object that carries the file name and its bytes. The script then receives a PSUFile, the same object it gets from the upload in the console.
I tested this on PowerShell Universal 2026.3.3 and 2026.3.4 with a script declaring param([File]$File). It ran in the Integrated, PowerShell 7 and Windows PowerShell 5.1 environments, and I called Invoke-PSUScript from both PowerShell 7 and Windows PowerShell 5.1, on the server and from another machine. Every time, the script received a PowerShellUniversal.PSUFile with the right file name and the full content, and files up to 60 MB arrived intact.
Replace File with the name of your parameter, put in your own path and script name, and add the connection parameters you already use.
$bytes = [IO.File]::ReadAllBytes('C:\temp\input.txt')
Invoke-PSUScript -Name 'YourScript.ps1' -Parameters @{ File = [pscustomobject]@{ FileName = 'input.txt'; Content = $bytes } }
Inside the script, $File.FileName is the name you set, and $File.Content is the byte array the parameters page describes.
https://docs.devolutions.net/powershell-universal/automation/scripts/parameters/#file
PSU saves the file's content with the job's parameters, so very large files make your database grow.
If the file does not arrive, please send me the error from the job's output and your PowerShell Universal version, with any app token removed.
Best regards,
Michel
Michel Audi