简体   繁体   English

在PowerShell中将数组传递给-FilePath参数

[英]Passing array to -FilePath parameter in PowerShell

I'm using invoke-command to execute a list of scripts on remote servers. 我正在使用invoke-command在远程服务器上执行脚本列表。 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. 这给我一个错误:Invoke-Command:FilePath参数的值必须是Windows PowerShell脚本文件。 Enter the path to a file with a .ps1 file name extension and try the command again. 输入文件扩展名为.ps1的文件的路径,然后重试该命令。 Parameter name: filePath 参数名称:filePath

If I replace the array with the absolute path to an individual script file, it works without issue. 如果我用单个脚本文件的绝对路径替换数组,则它可以正常工作。

Thanks! 谢谢!

No, it takes a single string only 不,只需要一个字符串

-FilePath <String>

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

Maybe try something like this: 也许尝试这样的事情:

Get-Content "Modules\\Modules.txt" | 获取内容“ Modules \\ Modules.txt” | foreach { invoke-Command "Modules\\$_" } foreach {invoke-Command“模块\\ $ _”}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM