问题
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