Applies to: Exchange Server 2010 SP3, Exchange Server 2010 SP2
Topic Last Modified: 2011-05-02
Each action that you take in the Exchange Management Shell must be done within the context of objects. The Shell uses structured collections of information called objects. These objects represent items in hierarchical data sources. When you call a cmdlet, one or more strongly typed structured objects are returned. Objects carry information about an item and about the object's structure. The object also acts as a proxy for the real item. For example, when you access a file from the Shell, you work with the object that represents that file, and not with the file itself.
Using objects gives the Shell an advantage over other traditional command shells. Traditional command shells have always supported the redirection of the output of one command to another in the form of a textual stream. This method has its disadvantages because parsing text has to be carefully controlled, usually by some kind of encoding to prevent unexpected behavior. By using objects, the Shell enables you to more easily choose the data you want to work with and use predefined methods to utilize and manipulate that data. You spend less time retrieving the data and more time using it.
The Exchange Management Shell uses this object model to pass information from one command to another by using pipelining. This avoids the problems caused by textual parsing in other command shells because the data that the Shell uses has a definite structure and is interpreted according to the object model.
For more information about pipelining, see Pipelining.
An object consists of three types of data: the object's type, its properties, and its methods.
The data type of an object provides details about what kind of object it is. For example, an object that represents a mailbox is a Mailbox object. An object that represents a file is a FileInfo object. All objects have a distinct predefined type and namespace that the Shell can process.
To see what object types are accepted and returned by cmdlets, see Cmdlet Input and Output Types.
A property is data associated with an object that specifies a particular state of that object. For example, a Mailbox object includes the property EmailAddresses. This object property represents the value of the actual attribute ProxyAddresses on mailbox-enabled Active Directory user accounts. This is the actual item represented by the Mailbox object.
The information about properties included with an object includes the current state and the definition of each property. This includes its name and the type of data that the property can take, such as Integer, Boolean, String, and so on.
A method is a set of instructions that defines a particular action that you can take on an object. Methods are defined based on the object type. For example, an object that is of type System.String, or String, has several methods that enable you to manipulate the string. Using the ToUpper() method on a string enables you to raise all of the characters within the string to uppercase. Some methods don't take arguments and some require arguments. It depends on the particular method you're using.
To call the methods available to an object, specify the method you want to use after the variable that the object is stored in. The variable and the method are separated by a period. The following example stores a string in the $Example variable and then calls the ToUpper() method to raise the string to uppercase.
$Example = "This is a string" $Example.ToUpper() THIS IS A STRING.
Notice that if you run
$Example again, the string itself hasn't been modified.
$Example This is a string.
To update the variable with the output of the method, you need to assign the output to the variable as shown in the following example.
$Example = "This is a string" $Example = $Example.ToUpper()
Now when you run
$Example, the string has been changed to uppercase in the variable.
$Example THIS IS A STRING.
If an object has properties, the properties can also have their own methods. As with objects, the type of the property defines what methods are available. The property type doesn't necessarily match the object type. To call a method on an object property, you use similar syntax to when you call an object method, but you include the property along with the object. For example, a Send connector object has a property called MaxMessageSize, which is of type ByteQuantifiedSize. One of the methods for the type ByteQuantifiedSize is ToMB(). The following command displays the value stored in MaxMessageSize.
$Connector = Get-ReceiveConnector "From Internet" $Connector.MaxMessageSize 10 MB (10,485,760 bytes)
If you now call the ToMB() method, the value stored in MaxMessageSize is displayed in megabytes.