I’m writing a big script for a server install, and I want it to be fully automatic, but also want developers to be able to fix it if it breaks (because it probably will!). To do this I imagine using Write-Output, Write-Debug, Write-Verbose, Write-Warning.
How do I get all of these Writes to be written (and time-stamped) to a .txt file? Also, I know that usually Write-Error is usually written in red, but there’s no color in .txt files. Is there a way to help distinguish them anyways, like maybe giving them a prefix to all the writes, like Debug, Warning, etc?
Oh, come on ! Why do you use text file old fashion logging that scatter information all over the operating system and need to be collected with tweezers by people who are in charge of the production ?
As PowerShell works on .NET you can use Even Tracing for Windows (ETW) or use the system log.
You can create and use one PowerShell log for all your scripts to publish details of the execution (information) and errors (in coordination with good exception handling) for people who are in charge of the production. You can dedicate a log for one script (as it exists a log for DNS etc.)
Here is an example (PowerShell V2 has it’s own CmdLets) :