Extending PowerShell Classes with Methods
We are in the middle of a series of articles teaching how to write PowerShell-based classes. This is a different kind of scripting technique, that I know you’ll find valuable once you have some experience. I’m still focusing on the mechanics of defining a PowerShell class. Eventually, we’ll look at how to incorporate them into your modules.
In the last article, I showed you how to define constructors for your class. This is the code that creates a new instance of your class. Remember, the class is nothing more than a software description of a thing that you want to manage. This thing will have properties that describe it. For much of your work, will probably be sufficient. But you can also provide a mechanism for the object to do something. Or you might do something to the object. This is an object method.
Let’s look at adding methods to the classes we’ve been using.