本文件已封存並已停止維護。

Working with Virtual Machine Manager Properties and Methods

更新日期: 2009年11月

適用於: Virtual Machine Manager 2008, Virtual Machine Manager 2008 R2, Virtual Machine Manager 2008 R2 SP1

When working with System Center Virtual Machine Manager (VMM) objects, you can use their properties and methods to manipulate data and take specific actions. Properties contain information about the state of an object. Methods are actions that you can perform on the item that an object represents. Methods can return data.

For more information about working with VMM objects, see Managing Objects in Virtual Machine Manager. For more information about working with Windows PowerShell objects, type Get-Help about_Objects at the command line.

Working with Properties

To get the properties of an object, use the MemberType parameter of the Get-Member cmdlet with a value of “property.” For example, to get the properties for a VMM server object, use the Get-VMMServer cmdlet to get the object that represents the VMM server. Then use the pipeline operator (|) to send the VMM server object to Get-Member.

Get-VMMServer -computername "VMMServer01" | Get-Member -membertype property

Property Values

To get the value for a property of an object, you can use the dot method. Type a reference to the object, such as a variable that contains the object or a command that gets the object. Then type a dot (.) followed by the property name.

For example, IsConnected is a Boolean property of a VMM server object that indicates whether the connection to the VMM server is open. If TRUE, the connection is open. If FALSE, the connection to the server has been closed. In the following example, the first command uses the Get-VMMServer cmdlet to get the object that represents VMMServer01 and then saves the object in the $Connection variable. The second command uses the dot method to display the value of the IsConnected property of the VMM server object in $Connection. In this example, the value returned is TRUE, indicating that the connection to VMMServer01 is open.


C:\PS> $Connection = Get-VMMServer -computername "VMMServer01"
C:\PS> $Connection.IsConnected
True

For more information about using properties with Windows PowerShell objects, type Get-Help about_Properties at the command line.

Working with Methods

To view the methods of an object, use the MemberType parameter of the Get-Member cmdlet with a value of “method.” For example, to get the methods for a VMM server object, use the Get-VMMServer cmdlet to get the object that represents the VMM server. Then use the pipeline operator (|) to send the VMM server object to Get-Member.

Get-VMMServer -computername "VMMServer01" | Get-Member -membertype method

To invoke a method, type a reference to the object, such as a variable that contains the object, and then specify the method name, separating the object reference and the method with a period. To pass arguments to the method, enclose the arguments in parentheses immediately following the method name. An empty set of parentheses indicates that the method requires no arguments; however, the empty set of parameters is still required.

For example, the Disconnect() method of a VMM server object closes the connection to the VMM server. This method does not take any arguments nor does it return data. In the following example, the first command uses the Get-VMMServer cmdlet to get the object that represents VMMServer01 and then saves the object in the $Connection variable. The second command uses the Disconnect() method to close the connection.


C:\PS> $Connection = Get-VMMServer -computername "VMMServer01"
C:\PS> $Connection.Disconnect()

For more information about using methods with Windows PowerShell objects, type Get-Help about_Methods at the command line.

另請參閱

顯示: