1.1. The Extended Type System

Rule number one for PowerShell is that everything is an object. Objects can have different types and origins and can contain various data too. Nevertheless, they must all look the same and expose services in a similar fashion, so that shell scripters do not need to learn different syntaxes for different objects. The first and most important characteristic of an object is its type. A type holds information about the operations that an object supports and is most often a .NET class. To get an object type, we use the GetType() method that all .NET objects have:

PS C:\> (42).GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Int32 System.ValueType PS C:\> "Hello, world".GetType() IsPublic ...

Get Pro Windows PowerShell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.