Powershell Invoke-Command with-FilePath Gives ItemNotFoundException

这一生的挚爱 提交于 2019-12-12 05:13:05

问题


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?


回答1:


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




回答2:


I was looking at this too long!

The error was relating to the local path of the file before it was copied to target server. I fixed this by changing the value for the -FilePath argument



来源:https://stackoverflow.com/questions/12478828/powershell-invoke-command-with-filepath-gives-itemnotfoundexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!