Behind the PowerShell Pipeline logo

Behind the PowerShell Pipeline

Subscribe
Archives
March 21, 2023

Advanced PowerShell Class Extensions

I think today’s article will be fun. We’ve been exploring how to write and use PowerShell classes in our scripting projects. I hope you’ve grabbed the demo code and have been trying things out for yourself. You should be able to create a basic class, perhaps with a method or two and a constructor.

Even though I mentioned last time that there are limitations to PowerShell classes, there are a few more developer-oriented features you can take advantage of. You may not need them for every class, but you should understand how to incorporate static methods and enums.

Static Methods

A static method is an object member that does not require an instance of the underlying class. When you run Get-Date, PowerShell creates an instance of a [DateTime] class.

Want to read the full issue?
GitHub Bluesky LinkedIn About Jeff
Powered by Buttondown, the easiest way to start and grow your newsletter.