how to pretty-print XML in PowerShell, and text pipelines

When I’ve needed to format an XML document nicely in PowerShell for the first time, I was pretty new to PowerShell. Doing it directly dind’t go too well but then I’ve found somewhere on the Internet an example that had shown me a different side of PowerShell, it really drove home the point that PowerShell is a shell…

1

how to run arbitrary commands as a service

I want to show how to run the arbitrary commands as a service, even a PowerShell script if you want. This started with Core .NET that currently doesn’t have the classes that support the services (although hopefully they will be added in the future). But overall I find pretty annoying that there is no easy…

2

Error handling part 6: ETW logging example

<< Part5 I want to show an example of how to do the error logging through ETW, for the error objects described in the Part 5. It goes against some of the commonly accepted ETW principles but I think that it would out better this way. I think that these commonly accepted ETW principles are…

0

reporting the nested errors in PowerShell

A pretty typical pattern for PowerShell goes like this: …allocate resource… try {   … process resource … } finally {   …deallocate resource… } It makes sure that the resource gets properly deallocated even if the processing fails. However there is a problem in this pattern: if the finally block gets called on exception…

0

reading the ETW events in PowerShell

When testing or otherwise controlling a service, you need to read its log that gets written in the form of ETW events. There is the basic cmdlet Get-WinEvent that does this but with it you can’t just read the events continuously. Instead you have to keep polling and connecting the new events to the previous…

0

expect in PowerShell

Like the other text tools I’ve published here, this one is not a full analog of the Unix tool. It does only the very basic thing that is sufficient in many cases. It reads the output from a background job looking for patterns. This is a very typical thing if you want to instruct some system do some…

0

booting Windows from a VHD

The easiest way to have multiple Windows versions available on the same machine is to place some of them into VHDs, and then you can boot an OS directly from a VHD. The boot loader stays shared between all of them on the original C: drive which might have or not have its own Windows…

0

localization both ways

The localization of messages on Windows is done through the MUI files. I.e. aside from mycmd.exe or mylib.dll you get the strings file mycmd.exe.mui or mylib.dll.mui, to be placed next to it in a subdirectory named per the language, like “en-us”, and the system will let you open and get the strings according to the user’s…

0

un-messing Unicode in PowerShell

PowerShell has a bit of a problem with accepting the output of the native commands that print Unicode into its pipelines. PowerShell tries to be smart in determining whether the command prints Unicode or ASCII, so if the output happens to be nicely formatted and contains the proper Unicode byte order mark (0xFF 0xFE) than it gets…

0

getting a stack trace in PowerShell

One of the most annoying “features” of PowerShell is that when the script crashes, it prints no stack trace, so finding the cause of the error is quite difficult. The exception object System.Management.Automation.ErrorRecord actually has the property ScriptStackTrace that contains the trace, it’s just that the trace doesn’t get printed on error. You can wrap…

0