0

我正在尝试Invoke-Sqlcmd并行运行两个,然后等待所有结果。

$server1 = '...'
$server2 = '...'

workflow work {
  parallel {
    $r1 = Invoke-Sqlcmd -ServerInstance $server1 'select 1 a'
    $r2 = Invoke-Sqlcmd -ServerInstance $server2 'select 2 a'
  }
}
work
# do something with $r1 and $r2. How to access the variables here?
  1. 如何传递$server1$server2到代码块?
  2. 如何获取$r1$r2从并行块?
4

1 回答 1

1

因此,使用参数传入服务器,并返回两个结果的哈希表。

$server1 = '...'
$server2 = '...'

workflow work {
  param ($server1, $server2)
  parallel {
    @{r1 = Invoke-Sqlcmd -ServerInstance $server1 'select 1 a'}
    @{r2 = Invoke-Sqlcmd -ServerInstance $server2 'select 2 a'}
  }
}
$r = work $server1 $server2
$r.r1
$r.r2
于 2019-10-29T02:51:08.563 回答