Compartir a través de


Using the Exchange Management Shell Cmdlet Response

Each Exchange Management Shell cmdlet returns one or more PSObject instances that provide a consistent view of any object in the Exchange Management Shell environment. This section provides information about how to use the properties of a PSObject instance to return the property values of the underlying Microsoft Exchange Server 2010 API object.

Using PSObject Instance Properties

The PSObject class exposes three public properties that contain the values of the underlying Exchange 2010 API object: the Properties, Methods, and Members properties. Each property that is exposed by the Exchange 2010 API object has a corresponding key/value pair in the Properties and Members properties. Your application can index the Properties collection by the name of a property to retrieve the value of the property.

You can use the TypeNames property of the PSObject instance to determine the type of the underlying Exchange object that is encapsulated by the PSObject instance. The TypeNames property is a collection of strings that contains the object hierarchy of the represented type. You can use these names to determine the object that is represented by the PSObject instance so that you can extract the appropriate property.

The following code example prints the contents of the Properties collection of a PSObject instance on the console. The code example requires a reference to the System.Automation.Management namespace.

Note

When you are using Microsoft Visual Studio to create an application, you must add a reference to the System.Mangagement.Automation.dll assembly to the project. The assembly can be found in one of the following locations:

  • For the Windows XP and Windows Vista operating systems, in the Windows PowerShell installation directory ($PSHOME).

  • For the Windows 7 operating system, in the following folder: Windows\assembly\GAG_MSIL\System.Management.Automation.

foreach (PSPropertyInfo propertyInfo in psObject.Properties)
{
    Console.WriteLine(string.Format("{0}: {1}",
        propertyInfo.Name, propertyInfo.Value);
}
For Each PropertyInfo As PSProperty In ObjectInfo.Properties
    Console.WriteLine(String.Format("{0}: {1}", PropertyInfo.Name, PropertyInfo.Value))
Next

Note

The code example requires a reference to the System.Automation.Management namespace.