0

I'm using invoke-command to execute a list of scripts on remote servers. I'm using a variable array to specify the scripts.

$Modules = Get-Content "Modules\Modules.txt"
$ModulePath = "Modules\" + $Module
Invoke-Command server -FilePath $ModulePath 

This gives me an error: Invoke-Command : The value of the FilePath parameter must be a Windows PowerShell script file. Enter the path to a file with a .ps1 file name extension and try the command again. Parameter name: filePath

If I replace the array with the absolute path to an individual script file, it works without issue.

Thanks!

2
  • 1
    Have you tried outputting $ModulePath to see exactly what it is you're sending to that parameter? Commented May 14, 2014 at 23:53
  • I have. The string output is the full path to the script file. Commented May 15, 2014 at 5:34

2 Answers 2

2

No, it takes a single string only

-FilePath <String>

http://technet.microsoft.com/en-us/library/hh849719.aspx

Sign up to request clarification or add additional context in comments.

Comments

2

Maybe try something like this:

Get-Content "Modules\Modules.txt" | foreach { invoke-Command "Modules\$_" }

2 Comments

Tried that with same results. Interesting to note. If I change $ModulePath to the full path of a single script it works. For example: $ModulePath = ".\Modules\Test.ps1"
Ok, that's right. My bad there. PowerShell will attempt to run from either its program folder or System32 (if in admin mode) if you don't specify the current dir. Glad it's working for you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.