Powershell: How to pass parameter with invoke-command and -filepath remotely?

怎甘沉沦 提交于 2019-12-11 00:48:08

问题


so there's a lot of similar topics to this I've found, but I can't find anything that correlates with my issue.

invoke-command -computername $serverLocation -Credential $cred -filepath "C:\path\script2.ps1" -ArgumentList $configPath

I am calling a for a script that is stored on my local machine to run on another server. Everything works as intended except for passing the "configPath" variable. This is how I initiate the script -

. .\script1.ps1 -serverLocation 'serverNameHere' -username 'userNameHere' -configPath 'configPathHere' 

It correctly grabs all the other parameters I pass into the first script. It just won't pass the configPath to the second script in the 'filepath'.

How can I get this parameter to pass through? Thanks so much.


回答1:


In script2.ps1, you should define a param() block that accepts the parameter, and then you can refer to it by whatever name you give it. If you don't want to use a param() block then using $args[0] should work.



来源:https://stackoverflow.com/questions/37465590/powershell-how-to-pass-parameter-with-invoke-command-and-filepath-remotely

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