Search code examples
powershellremoting

Powershell Invoke-Command with-FilePath Gives ItemNotFoundException


I establish a persistent session then attempt to execute a script remotely using the following line:

Invoke-Command -Session $Session  -FilePath "FullStopBizTalkApp.ps1"  -argumentlist $BizTalkMgmtDBConString, $ApplicationNameInBizTalk

If I then execute: $_.Exception.ToString() I can see the following error:

System.Management.Automation.ItemNotFoundException: Cannot find path 'C:\Users\tfs_service\FullStopBizTalkApp.ps1' because it does not exist.

I am able to invoke commands from the same client to the same target server when using -ScriptBlock, I only get the problem when using -FilePath

Any ideas?


Solution

  • Enter the path and file name of the script, or make sure your session working directory is the parent directory of the script file.