我在一个表中有一些行,其中有一个名为"query_server“的列。
Invoke_ASCmd命令必须在不同的查询服务器(称为Destination_server)上调用两次(2行),如下所示:
foreach($row in $Table | where { $_.cube_name -match $CUBE -and $_.active -match $Active })
{
$Destination_Server = $row.Item("query_server")
$sync_output += "_$Destination_Server.txt"
Invoke-ASCmd –InputFile $XML_file -Server $Destination_Server >$sync_output
}我试过这样做,但不起作用
$i=0
foreach($row in $Table | where { $_.cube_name -match $CUBE -and $_.active -match $Active })
{
@($Destination_Server) = $row.Item("query_server")
$sync_output += "_$Destination_Server.txt"
Invoke-ASCmd –InputFile $XML_file -Server $Destination_Server[$i] >$sync_output
$i++
}抛出错误:
发布于 2018-09-18 07:12:16
数组必须在foreach循环之外初始化。否则,它只能在循环的单个实例中使用。
试试这个:
$i=0
$Destination_Server = @()
foreach($row in $Table | where { $_.cube_name -match $CUBE -and $_.active -match $Active })
{
$Destination_Server += $row.Item("query_server")
$sync_output += "_$Destination_Server.txt"
Invoke-ASCmd –InputFile $XML_file -Server $Destination_Server[$Destination_Server.length -1] >$sync_output
$i++
}https://stackoverflow.com/questions/52380278
复制相似问题