From the course: PowerShell: Functions for Advanced Automation

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Work with classes

Work with classes

From the course: PowerShell: Functions for Advanced Automation

Start my 1-month free trial

Work with classes

- [Instructor] The best way to understand how to use .NET classes is probably to make one of our own. We can see how properties and methods work by creating some that we can use. PowerShell 5.0 introduced the ability to create classes, so what's what we're going to do. Consider an object that we're all familiar with, a wallet. A wallet has several properties. A wallet can be defined by its style, color, and the material it's made out of. It can also be defined by what's found inside. The name on the ID card and details of the available funds are important properties of a wallet. Each of these properties has an expected format, strings of text, floating point values and integers. So let's take a look at the code used to create a .NET class. I've created the code in PowerShell ISE so that you don't have to wait on my typing to see how this works. Take a look at the syntax to begin. It's pretty much the same as a function or several other blocks of code in PowerShell. Once we say that…

Contents