Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell ForEach只阅读文本的第一行_Powershell_Foreach - Fatal编程技术网

Powershell ForEach只阅读文本的第一行

Powershell ForEach只阅读文本的第一行,powershell,foreach,Powershell,Foreach,我有一个文本文件,其中我有多个文本,在不同的行是唯一的。我有点像: $submit = Get-Content submit.txt $submit| ForEach { function Query { ....} return 0 但是,它只读取第一行并将其解析为函数。它解析的行数与文本文件上的行数相同。如何让它逐个遍历每一行并将文本传递给函数?在进入循环之前,只需定义一次函数: # This will define the function so its available l

我有一个文本文件,其中我有多个文本,在不同的行是唯一的。我有点像:

$submit = Get-Content submit.txt 

$submit| ForEach {
function Query 


{ ....}
return 0

但是,它只读取第一行并将其解析为函数。它解析的行数与文本文件上的行数相同。如何让它逐个遍历每一行并将文本传递给函数?

在进入循环之前,只需定义一次函数:

# This will define the function so its available later, in the loop
function Query {
  param($Line)
  # ...
}

Get-Content submit.txt |ForEach-Object {
  # this actually executes the Query function
  Query -Line $_
}

function
关键字定义了一个函数,它不执行它。请修复您的代码示例(至少缺少1个
}
作为有效的powershell代码)有一个结尾}我只是没有将其添加到我的帖子中。我应该用什么来代替函数以使其循环?请创建一个。但是我的函数使用的是我正在从该文本文件解析的变量哪个变量<代码>美元?