Managing VMM Objects

 

Updated: May 13, 2016

Applies To: System Center 2012 R2 Virtual Machine Manager, System Center 2012 - Virtual Machine Manager

Windows PowerShell is based on object-oriented programming and Microsoft .NET Framework classes. An object contains the following types of data: the object's type, its methods, and its properties.

VMM Objects

When working with System Center 2012 – 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 Windows PowerShell objects, see about_Objects.

Properties

You can get the available properties of an object by using the Get-Member cmdlet and setting the MemberType parameter to "property". For example, to get the properties for a logical network, get the logical network object and then use the pipeline operator (|) to send the object to Get-Member.

PS C:\> Get-SCLogicalNetwork -Name "LogicalNetwork01" | Get-Member -MemberType property  
  
   TypeName: Microsoft.SystemCenter.VirtualMachineManager.LogicalNetwork  
  
Name              MemberType Definition  
----              ---------- ----------  
Description       Property   System.String Description {get;}  
ID                Property   System.Guid ID {get;}  
IsFullyCached     Property   System.Boolean IsFullyCached {get;}  
IsViewOnly        Property   System.Boolean IsViewOnly {get;}  
MarkedForDeletion Property   System.Boolean MarkedForDeletion {get;}  
Name              Property   System.String Name {get;}  
ObjectType        Property   Microsoft.VirtualManager.Utils.CarmineObjectType ObjectType {get;}  
ServerConnection  Property   Microsoft.SystemCenter.VirtualMachineManager.Remoting.ServerConnection Server...  

You can get the value for a property by using the dot method. Get a reference to the object, such as a variable that contains the object, or type a command that gets the object. Then, type a dot (.) followed by the property name. The following example gets the value for the Name property of a logical network object.

PS C:\> $LogNet01 = Get-SCLogicalNetwork -Name "LogicalNetwork01"  
PS C:\> $LogNet01.Name  
LogicalNetwork01  

For more information about Windows PowerShell properties, see about_Properties

Methods

You can get the available methods for an object by using the Get-Member cmdlet and setting the MemberType parameter to "method". For example, to get the methods for a logical network, get the logical network object and then use the pipeline operator (|) to send the object to Get-Member.

PS C:\> Get-SCLogicalNetwork -Name "LogicalNetwork01" | Get-Member -MemberType method  
  
   TypeName: Microsoft.SystemCenter.VirtualMachineManager.LogicalNetwork  
  
Name           MemberType Definition  
----           ---------- ----------  
CompareTo      Method     int CompareTo(System.Object obj)  
Equals         Method     bool Equals(System.Object obj)  
GetHashCode    Method     int GetHashCode()  
GetType        Method     type GetType()  
OnAddedToCache Method     System.Void OnAddedToCache()  
ToString       Method     string ToString()  

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. The following example uses the GetType method to return the base type of a logical network.

PS C:\> $LogNet01.GetType
()  
  
IsPublic IsSerial Name                                     BaseType  
-------- -------- ----                                     --------  
True     False    LogicalNetwork                           Microsoft.SystemCenter.VirtualMachineManager.Cl...  

For more information about Windows PowerShell methods, see about_Methods

Object Synchronization

VMM synchronizes its objects. That is, if you create two variables and then change a property of the object that is stored in either variable, VMM synchronizes the object property in both variables. The following example demonstrates how the name of a logical network object stored in two variables gets synchronized:

# Get LogicalNetwork01 and store it in a variable.  
PS C:\> $LogNet01 = Get-SCLogicalNetwork -Name "LogicalNetwork01"  
# Take a look at the name of the logical network stored in $LogNet01.  
PS C:\> $LogNet01.Name  
LogicalNetwork01  
  
# Get LogicalNetwork01 and store it in a second variable.  
PS C:\> $LogNet02 = Get-SCLogicalNetwork -Name "LogicalNetwork01"  
# Take a look at the name of the logical network stored in $LogNet02.  
PS C:\> $LogNet02.Name  
LogicalNetwork01  
  
# Change the name of the logical network object stored in $LogNet02  
PS C:\> Set-SCLogicalNetwork -LogicalNetwork $LogNet02 -Name "Backend"  
# Take a look at the name of the logical network stored in $LogNet02.  
PS C:\> $LogNet02.Name  
Backend  
  
# Now take a look at the name of the logical network stored in $LogNet01.   
# Note how the name property has been synchronized with the name change   
# made to the object stored in $LogNet02.  
PS C:\> $LogNet01.Name  
Backend  

See Also

VMM Cmdlet Help Topics