Search code examples
powershellffmpeginvoke-command

Call remote cmdlet (ffmpeg) via Invoke-Command: "... not recognized as the name..."


I'm trying to call ffmpeg on a remote transcoding server via Powershell:

$session = new-pssession -computername transcodingserver
Invoke-Command -session $session -scriptblock { powershell ffmpeg }

ffmpeg is correctly installed on the remote server and can be run there, but the remote call results in an error:

ffmpeg : The term 'ffmpeg' is not recognized as the name of a cmdlet, function, script file, or operable program.
    + CategoryInfo          : NotSpecified: (ffmpeg : The te...rable program. :String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
    + PSComputerName        : transcodingserver

Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ ffmpeg
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (ffmpeg:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
NotSpecified: (:) [], RemoteException

It seems to me like if the machine, I run Invoke-Command on, tries to run ffmpeg, which is not installed there. What do you have to do, to run ffmpeg on a remote server?


Solution

  • You don't need powershell inside -scriptblock {..} because Invoke-Command itself is a powershell session(albeit a temporary one). Find the full path to ffmpeg executable and run the following

    $session = new-pssession -computername transcodingserver
    Invoke-Command -session $session -scriptblock { & "C:\Program Files\ffmpeg\bin\ffmpeg.exe"}
    

    or you can execute the command directly, without new-pssession

    Invoke-Command -ComputerName transcodingserver -scriptblock { 
        & "C:\Program Files\ffmpeg\bin\ffmpeg.exe"}