PowerShell 技能连载 - 进度条技巧(第 3 部分)

PowerShell 内置的进度条可以嵌套,每个任务显示一个进度条。为了使其正常工作,请为您的进度条分配不同的 ID 号码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$servers = 'dc-01', 'dc-02', 'msv3', 'msv4'
$ports = 80, 445, 5985

$servers | ForEach-Object {
$server = $_
Write-Progress -Activity 'Checking Servers' -Status $server -Id 1

$ports | ForEach-Object {
$port = $_
Write-Progress -Activity 'Checking Port' -Status $port -Id 2

# here would be your code that performs some task, i.e. a port test:
Start-Sleep -Seconds 1
}
}

PowerShell 技能连载 - 进度条技巧(第 3 部分)

http://blog.vichamp.com/2023/05/17/progress-bar-tricks-part-3/

作者

吴波

发布于

2023-05-17

更新于

2023-05-22

许可协议

评论