I’m trying to call a .ps1 on remote servers, every attempt to pass arguments with Invoke-Command has failed me.
The .ps1 I’m calling has mandatory parameters, if I leave it I have it, I’m then prompted for those parameters (because my args aren’t passing), however no combination of " and ’ has been the answer for me. Putting the whole string in quotes gets me the error “test.ps1 -var1” is not a valid file. I’m using the PSsession because a stackoverflow I read suggested that helped them.
I cannot see anything which prompts for input in above code. If you have anything inside test.ps1, you have to parametrize and pass the value.
You don’t need to use the call operator(&), just remove the quotes. If you are executing only that script in scriptblock. You can use -FilePath parameter of Invoke-Command. Instead of explaining options. I would suggest you to read the documentation for Invoke-Command.
You don’t need to use PowerShell.exe here and should use Param() as I suggested before.
I reiterate , Please read the docs. It we can of course give you the solution and already gave the hints. but without reading the documentation, its going to put you in trouble for every new line of code you write.
I appreciate everyone’s help and don’t mean disrespect. When I turn to powershell.org it means all my internet searches and attempts on my own have failed. I’ve tried the $Using: method, and the most recent passing parameters. Here is my current code that is still yielding no passing of parameters. In the code below, the remote ps1 file test.ps1 does execute, however the parameters are passed as empty strings, which test.ps1 needs to have values to run its code.
I can write-output all of the variables inside of the foreach loop successfully, so I know they have the correct value inside of the loop. My best guess is the way I’m calling the script.