Syntax highlighting is one of the best features of a modern IDE or IDE-lite (such as VSCode). Things like IntelliSense, tab completion, matching token highlighting, go-to-definition, and more are all fantastic and make coding faster, easier, and more efficient (not to mention more accurate and consistent); however, a field of white text on a black background (or worse, black text on a white background) just makes everything look the same and hard to follow. Highlighting different tokens with different colors makes them stand out and makes it easier to tell what something is at a glance.
Read MoreChange Report: 2021
Okay, so, I've put it on my to-do list to actually post something here for the last...wait, it's been *three weeks* already?!? Time sure does fly...
Here I will detail upcoming changes to the site, as well as a status update on the error handling series.
Read MoreNew-PCBPost -Force
Don’t say I never post anything…just almost never…
Read MoreGet-XKCDCaldendarFact function
XKCD is one of my favorite webcomics, and so when I saw the calendar facts comic, I figured I could easily write a function that uses that as a basis. Something simple and fun.
Anyway, I've done so and posted it on my GitHub for this site (click here) for anyone who wants to play around with it. It's pretty easy to extend, change, or do whatever you want with.
I might even be open to extending it if anyone wants to fork it and send me a pull request.
Anyway, just some fun stuff. Enjoy!
Favicon (finally) added
Okay, my art skills aren't amazing by any stretch of the imagination, but I've been tired of seeing the default icon on my website. So, I've drawn a very simple 16x16 icon for it using favicon.cc.
That's all; nothing much exciting for today.
Font rendering issue with Edge browser
While checking on some things, I decided to load my site in Edge and was in for a bit of a shock: my site was rendered with what appears to be Times New Roman. After validating that I did in fact have fonts configured properly, I did a bit of research on how to fix it, and the short answer is, I can't (at least, not easily). It's a bug in Edge that's been going on for a while now.
Here's a post from almost two years ago about the problem. The best response is towards the end (next to last reply at the time of writing, on October 13th of 2016) and breaks down what is happening and what individuals can do to correct it.
I want to be clear here that I think Edge is overall an excellent browser with a lot of potential, but these sorts of bugs are really problematic and I hope that Microsoft is taking them seriously.
Error Handling: Basic Primer
It happens: you run a script or execute a command, and something doesn't work quite right. You get an ugly red error. Now what?
There are many ways to handle this. When you're sitting at the console, frequently it comes down to simply reading the error message and figuring out what you forgot or mistyped. These are often the easiest errors to deal with just for the fact that they're interactive by nature, so you get the opportunity to try other things until you get the results you're looking for before proceeding.
Things get a lot more complicated, however, when you're writing a script, especially one that is meant to run without someone sitting at a console to see the errors. At least if the script is being run manually, the person sitting at the console will be able to see that something did go wrong; when it's unattended, though, frequently you wind up losing valuable clues as to what went wrong, so you need to think about how your script could fail and account for that ahead of time with error handling.
Read MorePowerShell GUI Framework now available →
A couple of years ago, I needed to build a tool for first tier helpdesk workers who didn't know PowerShell. I pitched to purchase a license of PowerShell Studio, but that was shot down as too expensive. So, instead, I decided to build my own GUI tool from the ground up and got to work researching how to do that.
Check it out here, or read on for more details.
Read MoreUseful [String] manipulation techniques with .Methods()
Many times when working with PowerShell, I find myself needing to manipulate text strings. There are a ton of ways you can manipulate strings, and a lot of those are thanks to the built-in methods included on all string objects.
I've covered some of my favorite string manipulation techniques for you here.
Read MoreOne Neat Trick to take objects apart: ConvertTo-JSON
One of the neatest tricks I've come across recently has to do with a need I find I have frequently: to be able to see the full structure of my output. Get-Member and Select-Object * are powerful, but have limits when it comes to discovery.
I go over the PowerShell v3 cmdlet ConvertTo-JSON in this post to look an another way to see what's really in your output.
Read MoreThe (very basic) Anatomy of an Object
Everyone who works with PowerShell beyond a rudimentary level could benefit from a basic understanding of .NET objects.
This post won't show you everything, but it might help peel the curtain back a little to get you started.
Read MoreExecution Policy is not a security countermeasure (Part 2: Group Policy)
In my last post, I wrote about how setting the Execution Policy is not a viable security countermeasure, and is very easy to bypass by malicious actors. The examples provided work when the Execution Policy is set by running "Set-ExecutionPolicy"; however, it does not bypass an Execution Policy set by Group Policy.
This post will demonstrate a way to get around that as well.
Read MoreExecution Policy is not a security countermeasure
While there are some benefits to signing your PowerShell code, security really isn't one of them. If something is run on your system that attempts to execute a malicious PowerShell script, it does not matter what your Execution Policy is set to.
Read on for a brief explanation of what Execution Policy actually affects, and a demonstration of how easy it is to bypass.
Read MoreScripting Games: January 2016
It's been a while, but I'm back. I decided to tackle this month's Scripting Games puzzle, and I found that it's basically something I've previously written with some modifications. So, I used that, made the necessary tweaks to fit their guidelines, and made some improvements over what I'd done at the time (it was a couple of years ago, and I'd like to think I've gotten at least a little better since then...)
Read MoreScripting Games: September 2015
For this month's Scripting Games, I get to trick the pipeline and play with text encoding! Fun stuff.
Read MoreI'm now on GitHub
As I mentioned in a previous post, I now have a GitHub account; all of my small code samples will be hosted there as gists, bigger functions will be added to my "poshsite" repository, and bigger projects will get their own repositories. I've removed all of the directly embedded code from this site and converted them to gists; this will give me a better place to store and share my code, and it provides much better syntax highlighting than what I was previously using.
That's not even getting in to the fact that it tracks changes for me automatically.
Anyway, you can find me at https://github.com/poshcodebear, and my gists at https://gist.github.com/poshcodebear.
Scripting Games: July 2015
The Scripting Games puzzle for July 2015 is underway (almost over, actually); here's my solution.
Read More