Behind the PowerShell Pipeline logo

Behind the PowerShell Pipeline

Subscribe
Archives
July 19, 2022

Wading into the Stream

In the last article, we looked at several logging techniques you can use in your PowerShell scripting. I focused on writing text-based files as I expect this is what most of you use if you are incorporating logging into your work. While we looked at Out-File and Add-Content, those aren’t our only options. The cmdlets are easy to use and are documented. They even support features like -WhatIf. I typically recommend PowerShell scripters use cmdlets wherever possible. But if you want to get your hands dirty with a little .NET code, there are a few other techniques on the table. These are techniques that could serve as the basis for your logging functions.

Meet the StreamWriter

One reason that PowerShell is so popular is that there are options. This is also why you can’t be trained in PowerShell. There are always several ways to complete a task in PowerShell. You need to learn PowerShell so that you can find the best solution for your automation or scripting context. I’ve been demonstrating a number of techniques for creating text-based log files. Here’s one more, although it requires some .NET scripting, and that is, the StreamWriter.

Want to read the full issue?
GitHub Bluesky LinkedIn About Jeff
Powered by Buttondown, the easiest way to start and grow your newsletter.