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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.