I recently starting looking at the subreddit for PowerShell, and I’ve seen a lot of people using hashtables for just about everything. I’ve even seen a few people using them over at PowerShell.com and in both cases the usage was dubious at best. Here are my thoughts on it, and why hashtables are usually not the right choice.
My daughter has really been working on her multiplication tables this year and normally she comes home with a study sheet for each number, all the way up to 12. This week we’re working on 8′s, so 8×0, 8×1, all the way up to 8×12. Unfortunately she didn’t get a worksheet so she decided to make her own. If I can take a moment of fatherly pride, she does this kind of thing all the time without us making her. What a gal! Well, one of the ways I motivate her is to race her. So it was on. Can I write a PowerShell script and get the multiplication table out before she could write it out?!
Got a couple of new scripts I recently wrote, here’s some quick thoughts on them.
Really fascinating project came through Spiceworks the other day and I wanted to talk about it. In the DNS forum someone posted that they needed a tool to lookup certain WhoIs information. The interesting part was they had over 1000 domains so they needed something that could create a report on that kind of scale, so a simple WhoIs website or application wasn’t going to cut it. But as I looked at it, I began to wonder if this was something I could pull off with PowerShell? I knew there would be no problem once I had the data, but the trick would be getting the data. But surely there was a RESTful API out there for WhoIs data, right? If I could find that then a simple Invoke-RestMethod should retrieve the data necessary and we’re good to go. Right?
As a follow-up to the ConvertTo-AdvHTML function, I have also written a much simpler version that simply changes the color of a cell. The advantage to this script over the bigger ConvertTo-AdvHTML function is it works with current ConvertTo-HTML, or even HTML pages from other sources. It also allows you the ability to set the criteria for the the color change. Best of all it’s simple to use.
I love using ConvertTo-HTML. There, I’ve said it. The vast number of scripts I write are doing some kind of reporting function and the ability to create simple, fast, yet good looking reports with HTML has been a huge plus for PowerShell. That said though, there’s definitely room for improvement. ConvertTo-AdvHTML is an advanced function that addresses some of the current limitations with current cmdlet. But this blog post isn’t going to a long explanation of how to use the new cmdlet, instead I wanted to write a script that actually used it.
This has come up a couple of times and I’ve always managed to work around it, but there will come a time when you want to create an advanced function or script. One with many parameters, and some of those parameters will be mutually exclusive. You can do this using the ParameterSetName argument, inside the Parameter decorator. Here’s how!
The other day I mentioned I was having a really bad day–that after being recognized turned into a really good day. The reason it was though was because my shiny new firewall from Meraki was having all kinds of problems keeping a reliable site-to-site VPN with my co-host site. The remote firewall was a Cisco ASA 5510 so you would have thought this wouldn’t be a problem! But it was, and from it arose a need to create something that could monitor if my multiple subnets were routing properly. The funny thing was I had recently helped another Spicehead with a similar script! Now I needed it!
Had a great time creating the Out-LastEarthquake.ps1 script, but let’s face it, other than it’s cool factor it doesn’t have much use. But what we do have is the framework for the ability to place markers on a Google Map, and there are definitely some uses for that. I created a proof of concept script that shows just what you could do.