Foreach - 并行没有输出返回 n Powershell 7
Foreach -Parrallel no output returned n Powershell 7
这听起来像是一个愚蠢的问题,但是当我 运行 在 Powershell 7 中使用 -Parallel 开关执行以下命令时,当我删除 -Parallel 时,该命令没有显示预期的输出切换我得到预期的输出。
测试.ps1文件是:
Get-Date
$hostname = hostname
Write-Host "$hostname"
-Parallel 命令:
(Measure-Command {$comps = Get-Content C:\temp\vms.txt | foreach -Parallel {Invoke-Command -ComputerName $_ -FilePath {C:\temp\test.ps1} -Verbose}}).Seconds
工作命令:
(Measure-Command {$comps = Get-Content C:\temp\vms.txt | foreach {Invoke-Command -ComputerName $_ -FilePath {C:\temp\test.ps1} -Verbose}}).Seconds
当我 运行 工作命令时,我得到下面的输出,虽然我仍然没有得到 Get-Date
输出
主机名1
主机名2
主机名 3
我想 运行 向带有 Catch
的多个 VM 命令,因此如果操作失败,我会返回一些信息。
有什么想法吗?
提前致谢:)
$comps = Get-Content C:\temp\vms.txt
invoke-command -ComputerName $comps -FilePath C:\temp\test.ps1
Invoke-command 已经并行运行。
这听起来像是一个愚蠢的问题,但是当我 运行 在 Powershell 7 中使用 -Parallel 开关执行以下命令时,当我删除 -Parallel 时,该命令没有显示预期的输出切换我得到预期的输出。
测试.ps1文件是:
Get-Date
$hostname = hostname
Write-Host "$hostname"
-Parallel 命令:
(Measure-Command {$comps = Get-Content C:\temp\vms.txt | foreach -Parallel {Invoke-Command -ComputerName $_ -FilePath {C:\temp\test.ps1} -Verbose}}).Seconds
工作命令:
(Measure-Command {$comps = Get-Content C:\temp\vms.txt | foreach {Invoke-Command -ComputerName $_ -FilePath {C:\temp\test.ps1} -Verbose}}).Seconds
当我 运行 工作命令时,我得到下面的输出,虽然我仍然没有得到 Get-Date
输出
主机名1 主机名2 主机名 3
我想 运行 向带有 Catch
的多个 VM 命令,因此如果操作失败,我会返回一些信息。
有什么想法吗?
提前致谢:)
$comps = Get-Content C:\temp\vms.txt
invoke-command -ComputerName $comps -FilePath C:\temp\test.ps1
Invoke-command 已经并行运行。