The task in Beginner’s Event 2 was to list out how a computer’s installed True Type fonts, and print a count of them (and of the total fonts). This really isn’t worth explaining, because it’s so simple, but again, the Scripting Guys Solution uses these extremely wordy mechanisms that make everything seem like so much work … I felt like I had to post a couple of alternate solutions. Lets start with the cleanest. Oh, and by the way, the code reads a lot better if you click through to the wider single-article layout of my site.
Notice the total lack of the statement for or foreach? That’s a beautiful thing. My favorite part is the line $ttf = $fonts -match "TrueType". Filtered array assignment works with any comparison operators, it’s very nice. Please use it. And yes, if all you wanted was to print out the TrueType font names, this one-liner would suffice:
Ok, for those of you who just can’t stand not having counter variables … do yourself a favor, and at least learn the syntax for switch -regex: