Using Write-Verbose in Scripts and Output Files
2 Nifty little tricks I learned today on Write-Verbose.
Using Write-Verbose in a Script
If you want to add verbose logging to your script (Note Script not function!) you just need to add:
This means you can then doing like:
When we run the script normally. We will see no results. But when we run it with -verbose will see the messages:
Using Write-Verbose in an Output File
As the Write-Verbose doesn’t use the normal output streams you cant (sadly there is a connect item for it!) just use
If you do it will just create a blank file.
What you need to do is use the 4> which opens the specific stream to get out the Verbose results.
this will get a text file that looks like:
Pretty cool (well I enjoyed it) 🙂