One of the features we’re working on in the latest version of PowerShell is the ability to define custom classes.
If you’ve ever used a PSCustomObject or a Hashtable in a script for storing related data, you’ll probably find classes to be a useful addition to your scripting toolkit.
While PSCustomObjects and Hashtables let you group related data, what if you want to perform actions on that data? For example:
This is the kind of scenario that classes really excel at. You use classes for holding “buckets” of related data, and operations on that date.
While the release notes in the V5 Preview (and of course, upcoming actual documentation) give an overview of how to define a class in PowerShell, here’s what they end up looking like:
And in use:
PS C:\temp> c:\temp\point.ps1 | Format-Table -Auto X Y - - 10 20
Now, if you wanted to extend this concept far further than you would ever want to, you might get this 🙂
And Show-BoxDemo in all of its glory. TAB switches between objects, and there are a few other hotkeys in the source.
And if you’re curious: