file operations and search recipes

See also: all the recipes and the intro # find all the files *.txt recursively under a directory, like Unix find dir /s /a dir\*.txt # in PowerShell dir -Recurse -Force “dir\*.txt” # search for text in the files, like find -exec grep # /s is recursive, /r is regexp, /i is ignore-case findstr /s…

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

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

diff in PowerShell

I have previously shown a variety of sed implemented in PowerShell. Here is another tool from the same series: diff in PowerShell. It’s not fancy and not fast but it does the basic work, and is fully portable in PowerShell. Took me about a couple of hours to write. It gets used like this: $diff =…

0

sed in PowerShell

One of the things that had been annoying me in PowerShell is the lack of sed, the Streaming text EDitor. So I’ve made my own. Like other things in PowerShell, it’s not the same, it’s much more verbose in usage than the original sed, so that it can’t really be used as an one-liner. On the other…

0