From the course: Complete Guide to PowerShell 7
Unlock this course with a free trial
Join today to access over 24,500 courses taught by industry experts.
Extending objects with methods - PowerShell Tutorial
From the course: Complete Guide to PowerShell 7
Extending objects with methods
- [Instructor] Extending objects with methods allows you to tailor their behavior to suit your needs. For example, adding a method to calculate an employee's annual salary based on their hourly rate makes the object more useful and reduces repetitive calculations. It also enhances the logic of the object itself, and, of course, enhances its overall usability. Adding methods to objects unlocks new possibilities for interacting with data. Data validation ensures consistent high quality transformation. Transformation methods make reformatting or adapting data effortlessly. Aggregation methods simplify computations. And chaining operations provide a way to streamline tasks that involve multiple steps. These types of scenarios demonstrate the diverse use cases for extending objects. The add-member with -member type script method can be used to define methods. Use $this to refer to the object instance inside the method, and then, of course, apply a dynamic behavior such as methods can call…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
(Locked)
Understanding PowerShell objects5m 6s
-
(Locked)
Inspect objects with Get-Member10m 55s
-
(Locked)
Select object properties5m 51s
-
(Locked)
Sorting objects3m 45s
-
(Locked)
Filtering objects4m 33s
-
(Locked)
Creating custom objects8m 27s
-
(Locked)
Extending objects with methods10m 26s
-
(Locked)
Converting objects to different formats9m 17s
-
(Locked)
-
-
-
-
-
-
-
-