PowerShell Workflow 中的並行和順序執行是如何工作的?


PowerShell 工作流是在多於一個節點上並行執行指令碼的最佳方式,這節省了產生輸出的大量時間,但是我們不總是希望並行地執行所有命令,但還需要其中一些按順序執行,我們可以使用 PowerShell 工作流來設計並行和順序命令。

Workflow TestWorkflow{
   parallel{
      Command1
      Command2
   }
   Sequence{
      Command3
      Command4
   }
}

TestWorkflow

在上面的程式碼中,Command1 和 Command2 將按任意順序並行執行,而 command3 和 command4 將按序列方式執行,因為它們在順序塊中,如下圖所示。

示例

Workflow TestWorkflow{
   parallel{
      Get-CimInstance Win32_LogicalDisk
      Get-CimInstance Win32_BIOS
   }
   sequence{
      Get-Service WinRM
      Get-Process Notepad++
   }
}

TestWorkFlow

輸出

TestWorkFlow

SMBIOSBIOSVersion : F.13
Manufacturer     : AMI
Name : F.13
SerialNumber : 5CD015JY8D
Version : HPQOEM - 1072009
PSComputerName :

DeviceID : C:
DriveType : 3
ProviderName :
FreeSpace : 219602677760
Size : 511123124224
VolumeName : OSDisk
PSComputerName :

Status : Running
Name : WinRM
DisplayName : Windows Remote Management (WS-Management)
PSComputerName : localhost

Id : 676
Handles : 738
CPU : 15.875
Name : notepad++
PSComputerName : localhost

更新時間: 2021 年 2 月 19 日

1 千+ 瀏覽

開啟你的 職業生涯

完成課程即可獲得認證

立即開始
廣告
© . All rights reserved.