Learn PowerShell: Episode 4, Types + Methods + Casting
Channel: ABMedia
Date: 2021-06-22

As we know very well by now, objects are the most central part of PowerShell, everything is built around them, and as such, there's quite a bit to them! In this video we're going to take a deeper look at objects than we have before, digging into some more of the smaller parts (members) they're made up of and much more!

Please note that I was a little sick while recording this so things definitely sound a little off in comparison to the previous videos, but shouldn't take too much away!

The video starts by continuing from the "cliffhanger" question of the last episode: How can we shorten down the process of adding note properties to an object? Well, we take a look at some aliases that can be used, some special parameters on the "Add-Member" command and more that help us shorten it down!

After that, the video dives into and takes a look at types, this is a key part of how the whole object system provided by .NET in PowerShell works and helps provide a very solid understanding of how properties and methods are dispatched to objects and how objects are grouped up within PowerShell.

We then take a look at how you can get the details of a type by its name, taking advantage of the special square bracket syntax within PowerShell to help us get a hold of specific details about a type, such as its full name, what properties it defines and much more.

Once we're learnt the square bracket syntax, we then link it to something we learnt in the last video, about how to convert from one type to another. We learn that doing this is called "casting", as well as some of the rules that apply to casting and what casts are most likely valid and what casts most likely aren't. 

The idea of casting is a lot clearer when we have knowledge of the central type system that objects follow within PowerShell, as we gain earlier in this video.

In this video, we also take a closer look at all of the smaller kinds of members you can get on objects. We go over note properties and properties, as we already covered in the last video, as well as briefly mentioning some of the other types, such as "ScriptProperty" and "CodeProperty". However, we then use this to take a look at the new, and final member we need to know about across this series.

This member is called a "Method" (also known as 'function' as you may have heard of), and it plays a very different role to properties, as shown in the video. Properties allow objects to store data and are the key pieces for allowing an object to represent a specific thing. However, in addition to storing data, different types of objects also have code attached to them, and this code is organised into blocks (single actions) called methods. Methods are actions you can perform and when you run them, they will perform a specific action.

We take a look at everything to do with methods, how they're run, whether they have parameters, whether they can give things back, their difference between commands, and how technically small it is and much more.

In addition, in this video, we also take a look at the type limiting that occurs very often within PowerShell, across properties, parameters, "return types" (explained in the video) and much more!

Hope you enjoy it!

Chapters:

0:00 Shortening Commands
5:00 Types
7:25 Casting In-Depth
9:00 Properties In-Depth
10:52 Methods
13:45 Auto Casting
18:00 Calling Methods
23:37 Type Analysis
26:35 Commands vs Methods

Thanks for watching my video, before are some general ABMedia links if you are interested:

Website ► https://abco.live/
Discord ► https://abco.live/discord

The Discord server is a place to chat with the creator of this video, as well as anyone who contributed to its development and has helped support ABWorld over the years.

A huge thank you goes to @ndumiphotos (on Instagram) for the graphics used in the intro.

#learnpowershell #powershell