Advertisement
realslacker

Write-Progress ErrorAction Demo

Apr 29th, 2020
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Test-Progress {
  2.  
  3.     [CmdletBinding()]
  4.     param()
  5.  
  6.     for ( $i = 0; $i -lt 30; $i ++ ) {
  7.  
  8.         Write-Progress -Activity Test -Status Test -PercentComplete ( $i / 30 * 100 )
  9.  
  10.         if ( $i -eq 10 ) {
  11.  
  12.             Write-Error 'Test Error'
  13.  
  14.         } else {
  15.  
  16.             Write-Host 'No Error'
  17.  
  18.         }
  19.  
  20.         Start-Sleep -Milliseconds 500
  21.  
  22.     }
  23.  
  24. }
  25.  
  26. #Test-Progress -ErrorAction Stop
  27.  
  28. Test-Progress -ErrorAction Continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement