Observations on writing to Screen and File in PowerShell

When writing a PowerShell script, you are typically doing “something” with “something” and getting a result based on this “doing”.

This is all well and good, but after you have gotten your result what do you do with the data? Two common scenarios are writing the result either to the screen or to a file. If the script is doing a lot of calculations, it’s quite common to also give the user some kind of feedback while it’s working, to indicate that it’s actually doing what it’s suppose to do and that it haven’t stalled. (more…)

The quest for speed – Finding files

A while back I wrote a post about handling files in PowerShell. In it I describe the different ways you can read and write files. You can read it here if you like: Working with files in PowerShell. This time I will discuss how to find files. You have undoubtedly been in a situation where you need to locate a file on your disk, but didn’t know exactly where to look. Or perhaps you need to get all log-files in a share? Or document how many mp3 files you find on the server hosting all your users profiles? (more…)

Get-Random vs System.Random

In the process of learning PowerShell it is customary to hear people say that you shouldn’t re-invent the wheel; if there is a native command for it, you should use that. And I agree. But there is a case to be made for taking the time to properly explore all the different options available to you. For instance when coding for a specific version of PowerShell, or if speed is important. This post will discuss the latter; specifically a comparison of the native command for generating random numbers (Get-Random) and using the .NET class System.Random. (more…)