# write-progress and debug

**URL:** <https://forums.powershell.org/t/write-progress-and-debug/148>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/write-progress-and-debug/148 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/write-progress-and-debug/148/1 "2011-12-31T18:30:00Z")

</div>

by turbomcp at 2012-09-10 11:30:14

> hi there  
> another quick question  
> i have this script:  
> `#requires -version 2.0 <# author: demo date: 10/09/2012 purpose: Retrieve event idâ€™s from multiple machines and add to a CSV file. #> Try { $servers=get-content r:\scripts\servers.txt $date=(Get-Date).AddDays(-7) foreach ($server in $servers) { if (test-connection $server -quiet) { $get1+=get-eventlog -logname application -cn $server -after $date | ?{$.eventid -eq "902" -and $.entrytype -eq "error"} | select MachineName,EventID,EntryType,Message } } if ($get1) {$get1 | export-csv r:\scripts\app.csv -notypeinformation} else {"No matching system log events found…"} } Catch { "An error occurred" }`  
>   
>   
> so im looking for specific events on multiple machines  
> two things im missing is some kind of progress bar to show me whats the script doing and where did it get to and the second thing is i noticed if i changed some stuff i get "an error has accured" and i dont have any clue what error on what server(basicly the same thing as no.1:))  
>   
> how complicate is it to add a status bar with some ino?  
>   
>   
>   
> Thanks in advance

by DonJ at 2012-09-10 15:19:59

> Write-Progress is pretty easy, but if you want progress "statements" rather than a "progress bar" per se, use Write-Verbose instead. It is, for me, a lot easier to track "see where it got to" type stuff.  
>   
> If you add   
>   
> `[CmdletBinding()] Param()`  
>   
> To the top of your script, it’ll enable the -Verbose switch, which turns on Write-Verbose’s output.

by coderaven at 2012-09-10 16:33:09

> Getting error data from the catch block use the $\_ variable - $_.Exception._

_by DonJ at 2012-09-11 07:37:47_

> _Ugh, I hate relying on $_ for that - put the -ErrorVariable parameter on the failing command and capture the error into an explicit variable. Safer, and easier to read.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 9:02pm UTC](https://forums.powershell.org/t/write-progress-and-debug/148/2 "2024-05-16T21:02:23Z")

</div>


