Posts

Showing posts from December, 2018

Removing the First Item from an Array in PowerShell

This is a quickie, but I often find myself working with arrays of objects when I'm working on a PowerShell script.  Occasionally, I need to remove the first item from that array, which I've always done by using the array index:  $array = $array[1..($array.count - 1)] .  That certainly works, but it's also kindof ugly. Today, I learned a better way!  PowerShell does a neat trick with commas, the equals sign, and arrays.  If you're assigning an array to a comma delimited list of variables, the array automatically gets split between those variables.  I've used that in the past in situations like this: $IPAddress = "192.168.0.1" $First,$Second,$Third,$Fourth=$IPAddress.split(".") And, as you'd expect, that will split the IP Address into octets, with each one going into its named variable.  That's great, but what happens if you've got this situation? $IPAddress = "192.168.0.1" $First,$Second=$IPAddress.split("....

Syntax Highlighting in Notepad++

I do a lot of work with PowerCLI and my favorite text editor is Notepad++ .  Recently, I've been adding more modules to my repertoire ( PowerNSX and PowerVRNI , I'm looking at you!) and I've finally decided that I need to add all of these modules' cmdlets to my syntax highlighting in NPP.  The proper way to do this is to define a custom language and add everything to it.  This can be done through the GUI (yuk) or by editing a custom language xml file. Unfortunately, there's no way to clone an existing language as a start for a custom language (or at least, I couldn't find a way to do it).  Even more unfortunately, the custom language definitions file syntax is pretty different from the inbuilt ones, so you can't just copy and then edit the XML from the already existing PowerShell language. Not if you want to do it the proper way.  It looks to me like I can trivially edit my default langs.xml file (where PowerShell is defined) and add an arbitrary set o...