Write-Progress

PowerShell 명령 창 내에 진행률 표시줄을 표시합니다.

Syntax

Write-Progress
     [[-Activity] <String>]
     [[-Status] <String>]
     [[-Id] <Int32>]
     [-PercentComplete <Int32>]
     [-SecondsRemaining <Int32>]
     [-CurrentOperation <String>]
     [-ParentId <Int32>]
     [-Completed]
     [-SourceId <Int32>]
     [<CommonParameters>]

Description

cmdlet은 Write-Progress 실행 중인 명령 또는 스크립트의 상태 보여 주는 PowerShell 명령 창에 진행률 표시줄을 표시합니다. 막대가 반영하는 표시기와 진행률 표시줄 위와 아래에 표시되는 텍스트를 선택할 수 있습니다.

PowerShell 7.2는 POWERShell이 ANSI 이스케이프 시퀀스를 사용하여 특정 정보를 표시하는 방법을 제어하는 데 사용되는 자동 변수를 추가 $PSStyle 했습니다. $PSStyle.Progress 멤버를 사용하면 진행률 보기 표시줄 렌더링을 제어할 수 있습니다.

  • $PSStyle.Progress.Style - 렌더링 스타일을 설정하는 ANSI 문자열입니다.
  • $PSStyle.Progress.MaxWidth - 뷰의 최대 너비를 설정합니다. 기본값은 120입니다. 최소값은 18입니다.
  • $PSStyle.Progress.View - 값 Minimal 이 있는 열거형 및 Classic. Classic 는 변경 없이 기존 렌더링입니다. Minimal은 최소한의 단일 줄 렌더링입니다. 기본값은 Minimal입니다.

자세한 $PSStyle내용은 about_ANSI_Terminals.md를 참조 하세요.

참고 항목

호스트가 가상 터미널 $PSStyle.Progress.View 을 지원하지 않는 경우 자동으로 로 설정 Classic됩니다.

예제

예제 1: For 루프의 진행률 표시

for ($i = 1; $i -le 100; $i++ ) {
    Write-Progress -Activity "Search in Progress" -Status "$i% Complete:" -PercentComplete $i
    Start-Sleep -Milliseconds 250
}

이 명령은 1에서 100까지 계산되는 루프의 for 진행률을 표시합니다.

cmdlet에는 Write-Progress 작업의 상대적 완성도를 나타내는 상태 막대 머리글Activity, 상태 줄 및 변수 $i (루프의 카운터for)가 포함됩니다.

예제 2: 중첩된 For 루프의 진행률 표시

$PSStyle.Progress.View = 'Classic'

for($I = 0; $I -lt 10; $I++ ) {
    $OuterLoopProgressParameters = @{
        Activity         = 'Updating'
        Status           = 'Progress->'
        PercentComplete  = $I * 10
        CurrentOperation = 'OuterLoop'
    }
    Write-Progress @OuterLoopProgressParameters
    for($j = 1; $j -lt 101; $j++ ) {
        $InnerLoopProgressParameters = @{
            ID               = 1
            Activity         = 'Updating'
            Status           = 'Progress'
            PercentComplete  = $j
            CurrentOperation = 'InnerLoop'
        }
        Write-Progress @InnerLoopProgressParameters
        Start-Sleep -Milliseconds 25
    }
}

Updating
Progress ->
 [ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo]
OuterLoop
Updating
Progress
 [oooooooooooooooooo                                                   ]
InnerLoop

다음은 진행률 보기를 Classic 각각 진행률 표시줄로 나타내는 두 개의 중첩된 for 루프의 진행률을 설정하는 예제입니다.

두 번째 진행률 표시줄의 명령에는 Write-Progress 첫 번째 진행률 표시줄과 구분하는 Id 매개 변수가 포함됩니다.

Id 매개 변수가 없으면 진행률 표시줄이 다른 매개 변수 아래에 표시되는 대신 서로 중첩됩니다.

예제 3: 문자열을 검색하는 동안 진행률 표시

# Use Get-WinEvent to get the events in the System log and store them in the $Events variable.
$Events = Get-WinEvent -LogName system
# Pipe the events to the ForEach-Object cmdlet.
$Events | ForEach-Object -Begin {
    # In the Begin block, use Clear-Host to clear the screen.
    Clear-Host
    # Set the $i counter variable to zero.
    $i = 0
    # Set the $out variable to an empty string.
    $out = ""
} -Process {
    # In the Process script block search the message property of each incoming object for "bios".
    if($_.message -like "*bios*")
    {
        # Append the matching message to the out variable.
        $out=$out + $_.Message
    }
    # Increment the $i counter variable which is used to create the progress bar.
    $i = $i+1
    # Determine the completion percentage
    $Completed = ($i/$Events.count) * 100
    # Use Write-Progress to output a progress bar.
    # The Activity and Status parameters create the first and second lines of the progress bar
    # heading, respectively.
    Write-Progress -Activity "Searching Events" -Status "Progress:" -PercentComplete $Completed
} -End {
    # Display the matching messages using the out variable.
    $out
}

이 명령은 시스템 이벤트 로그에서 "바이오s" 문자열을 찾는 명령의 진행률을 표시합니다.

PercentComplete 매개 변수 값은 처리된 이벤트 수를 검색 $Events.count$i 총 이벤트 수로 나눈 다음 그 결과를 100으로 곱하여 계산됩니다.

예제 4: 중첩된 프로세스의 각 수준에 대한 진행률 표시

$PSStyle.Progress.View = 'Classic'

foreach ( $i in 1..10 ) {
  Write-Progress -Id 0 "Step $i"
  foreach ( $j in 1..10 ) {
    Write-Progress -Id 1 -ParentId 0 "Step $i - Substep $j"
    foreach ( $k in 1..10 ) {
      Write-Progress -Id 2  -ParentId 1 "Step $i - Substep $j - iteration $k"
      Start-Sleep -Milliseconds 150
    }
  }
}

Step 1
     Processing
    Step 1 - Substep 2
         Processing
        Step 1 - Substep 2 - Iteration 3
             Processing

이 예제에서는 ParentId 매개 변수를 사용하여 들여쓰기 출력을 사용하여 각 단계의 진행 중인 부모-자식 관계를 표시할 수 있습니다.

매개 변수

-Activity

상태 표시줄 위 제목의 첫 번째 텍스트 줄을 지정합니다. 이 텍스트는 진행률이 보고되는 있는 작업을 설명합니다.

Type:String
Position:0
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Completed

진행률 표시줄이 표시되는지 여부를 나타냅니다. 이 매개 변수를 생략 Write-Progress 하면 진행률 정보가 표시됩니다.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-CurrentOperation

진행률 표시줄 아래의 텍스트 줄을 지정합니다. 이 텍스트에서는 현재 수행 중인 작업에 대해 설명합니다.

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Id

각 진행률 표시줄을 다른 진행률 표시줄과 구별하는 ID를 지정합니다. 하나의 명령으로 여러 개의 진행률 표시줄을 만들 때 이 매개 변수를 사용합니다. 진행률 표시줄에 다른 ID가 없으면 계열에 표시되는 대신 중첩됩니다. 음수 값은 허용되지 않습니다.

Type:Int32
Position:2
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ParentId

현재 활동의 부모 활동을 지정합니다. 현재 활동에 부모 활동이 없는 경우 이 값을 -1 사용합니다.

Type:Int32
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-PercentComplete

완료된 활동의 백분율을 지정합니다. 완료 비율을 알 수 없거나 적용할 수 없는 경우 이 값을 -1 사용합니다.

Type:Int32
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-SecondsRemaining

작업이 완료될 때까지 기본 예상 시간(초)을 다시 지정합니다. 다시 기본 시간(초)을 알 수 없거나 적용할 수 없는 경우 이 값을 -1 사용합니다.

Type:Int32
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-SourceId

레코드의 원본을 지정합니다. Id 대신 사용할 수 있지만 ParentId와 같은 다른 매개 변수에는 사용할 수 없습니다.

Type:Int32
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Status

상태 막대 위의 제목에 있는 두 번째 텍스트 줄을 지정합니다. 이 텍스트는 활동의 현재 상태를 설명합니다.

Type:String
Position:1
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

입력

None

개체를 이 cmdlet으로 파이프할 수 없습니다.

출력

None

이 cmdlet은 출력을 반환하지 않습니다.

참고

진행률 표시줄이 나타나지 않으면 변수 값을 $ProgressPreference 검사. 값이 설정된 SilentlyContinue경우 진행률 표시줄이 표시되지 않습니다. PowerShell 기본 설정에 대한 자세한 내용은 about_Preference_Variables 참조하세요.

cmdlet의 매개 변수는 System.Management.Automation.ProgressRecord 클래스의 속성에 해당합니다. 자세한 내용은 ProgressRecord 클래스를 참조 하세요.