At this point, you know how to access the properties and methods of an object, but you need to be able to discover and work with these members. To determine which properties and methods are accessible on a given object, you can use the Get-Member cmdlet, which is one of the key discovery tools in PowerShell along with Get-Help and Get-Command.
To retrieve the members of an object, pipe the object to the Get-Member cmdlet. The following command will retrieve all of the instance members of the $mailbox object we created earlier:
$mailbox | Get-Member
To filter the results returned by Get-Member, use the -MemberType parameter to specify whether the type should be a Property or a Method.
Let's take a look at a practical example of how we could use Get-Member to discover the methods of an object. Imagine that each mailbox in our environment has had a custom MaxSendSize restriction set and we need to record the value for reporting purposes. When accessing the MaxSendSize property, the following information is returned:
[PS] C:\>$mailbox.MaxSendSize
IsUnlimited Value
----------- -----
False 50 MB (52,428,800 bytes)
We can see here that the MaxSendSize property actually contains an object with two properties: IsUnlimited and Value. Based on what we've learned, we should be able to access the information for the Value property using a dot notation:
[PS] C:\>$mailbox.MaxSendSize.Value
50 MB (52,428,800 bytes)
That works, but the information returned contains not only the value in megabytes, but also the total bytes for the MaxSendSize value. For the purpose of what we are trying to accomplish, we only need the total megabytes. Let's see if this object provides any methods that can help us out with this using Get-Member:
From the output shown in the previous screenshot, we can see this object supports several methods that can be used to convert the value. To obtain the MaxSendSize value in megabytes, we can call the ToMB method:
[PS] C:\>$mailbox.MaxSendSize.Value.ToMB()
50
In a traditional shell for Exchange on-premises, you would have to perform complex string parsing to extract this type of information, but PowerShell and the .NET Framework make this much easier. As you'll see over time, this is one of the reasons why PowerShell's object-based nature really outshines a typical text-based command shell.
An important thing to point out about this last example is that it would not work if the mailbox had not had a custom MaxSendSize limitation configured, which would be the case for newly created mailboxes in Exchange 2016, if not specified.
Nevertheless, this provides a good illustration of the process you'll want to use when you're trying to learn about an object's properties or methods.