This documentation is archived and is not being maintained.

Managing Objects in Virtual Machine Manager

Updated: January 7, 2010

Applies To: Virtual Machine Manager 2008, Virtual Machine Manager 2008 R2, Virtual Machine Manager 2008 R2 SP1

Windows PowerShell is based on object-oriented programming and Microsoft .NET Framework classes. Windows PowerShell is designed so that server administrators can quickly learn how to manipulate objects interactively by using commands or by using task-based scripts. All the entities in a System Center Virtual Machine Manager (VMM) environment are represented as objects. This topic provides a brief introduction to using objects in Windows PowerShell in the context of VMM.

Accessing Objects

Each object that the Windows PowerShell – Virtual Machine Manager command shell uses is an instance of a .NET Framework class, which consists of data and operations that are associated with that data. An object contains the following kinds of data:

  • Type. The type of the object indicates the kind of object it is. For example, the type for a VMM library server is TypeName: Microsoft.SystemCenter.VirtualMachineManager.LibraryServer.

  • Properties. The properties of the object are its characteristics. After you connect to the VMM database and then run a VMM cmdlet that contains the Get verb, you receive information about the state of each property for the VMM object. For example, the Get-VMHost, Get-VirtualNetwork, and Get-VirtualDVDDrive cmdlets return information about the state of each property of a VMM object.

  • Methods. The methods of the object are the actions that you can perform on the entity (such as a server or virtual machine) that the object represents.

When you call a cmdlet by typing the cmdlet name at the command prompt, the command shell returns the specified object. In a single command, you can use one or more pipeline operators (|) to pass an object from one cmdlet to another. You specify the properties and methods of the object by name.

All objects of the same type share the same properties and methods. However, each instance of an object can have different values for its properties. For example, all VMM library servers are the same type of object and share the same properties and methods. But, you typically define a different Name property and Description property for each library server object. Conversely, multiple servers might have the same value for the DomainName property. For more information about working with properties and methods, see Working with Virtual Machine Manager Properties and Methods.

Differentiating an Object from What It Represents

An object is not the same as the entity that the object represents. For example, a library server object is not the library server itself. Rather, it represents the physical file server that is configured as a VMM library server so that you can use cmdlets to perform operations on that server. You might use the Add-LibraryServer cmdlet to add a new library server object to the VMM database. Or, you might use the Get-LibraryServer cmdlet to retrieve the object that represents an existing library server and to view its properties.

Windows PowerShell arrays and VMM arrays are collections of objects of the same type. You might, for example, create an array that stores the object that represents each virtual machine that is turned off. Then, you might pass all these virtual machine objects to a cmdlet that starts each virtual machine in the array.

Viewing an Object

You can use the Get-Member cmdlet to view the properties and methods of any object. The object type appears at the top of the output in the following format.

TypeName: Microsoft.SystemCenter.VirtualMachineManager.Remoting.ServerConnection

Following the TypeName header, the output lists the name and the definition for all the methods and the properties that are associated with the VMM server object.

To display the type, methods, and properties for the Virtual Machine Manager server object

  1. On a VMM server on which the Administrator Console for VMM is installed, click Start, click All Programs, click Microsoft System Center, click Virtual Machine Manager 2008, and then click Windows PowerShell – Virtual Machine Manager.

  2. At the command prompt, type the following commands:

    $VMMServer = Get-VMMServer -Computername "<YourVMMServerName>.<YourDomainName>.com"
    $VMMServer | Get-Member
  3. Confirm that the output displays the object type, a set of methods, and a set of properties for the server object.

Managing Objects with Virtual Machine Manager Cmdlets

You can use VMM cmdlets to manage all the VMM objects at the command line. These objects are stored in a Microsoft SQL Server database called the VMM database. The database is stored on the VMM server or on a remote server running an instance of SQL Server that is associated with the VMM server.

The following objects are examples of VMM objects:

  • Computers. Objects that represent each type of physical or virtual computer in a VMM environment are stored in the VMM database. These servers include the VMM server itself, servers that act as hosts for virtual machines, servers that act as libraries to store resources, Web servers that act as Self-Service Portals, and virtual machines that are either deployed on a host or stored in the library.

  • Resources. Objects that represent library resources (such as library shares, virtual machine templates, ISO images, or scripts) that are stored in the library catalog in the VMM database. Files that these library objects represent are stored as specific file types on the physical library server.

  • Components of a virtual machine. Objects that represent parts of a virtual machine (such as virtual floppy drives, virtual network adapters, virtual SCSI adapters, or virtual COM ports) can be stored on a virtual machine, on a template, or on a hardware profile.

VMM cmdlets typically use standard Windows PowerShell verb names for similar actions performed on specific objects. Consider the following examples:

  • Cmdlets that contain the New verb are used to create new objects such as virtual machines, virtual network adapters, or templates. These cmdlets store the new objects in the VMM database.

  • Cmdlets that contain the Add verb are used to add an object to the VMM database for something that already exists, such as a library server, a library share, a host server, a host network adapter, or a virtual hard disk. Other objects are added to the database automatically.

  • Cmdlets that contain the Get verb are used to retrieve the object that represents a VMM entity such as a host, host group, virtual machine, template, script, or job from the VMM database. You can review the characteristics of the retrieved object, or you can use other VMM cmdlets to act on that object.

  • Cmdlets that contain the Set verb are used to specify or change the properties that are associated with an object.

  • Cmdlets that contain the Remove verb are used to remove an object from the VMM database.

Virtual Machine Manager Synchronizes Objects

VMM synchronizes VMM objects. When you create two variables and then change the name of an object that is stored in either variable, VMM synchronizes the object name in both variables. The following example demonstrates this synchronization.

To run the example, change the name of the VMMServer1 VMM server, the name of the LibServ01 library server, and the domain to the actual names of your VMM server, library server, and domain. The example assumes that the ISO image is named VMAdditions.

To observe how Virtual Machine Manager objects are synchronized

  1. On a VMM server on which the VMM Administrator Console is installed, click Start, click All Programs, click Microsoft System Center, click Virtual Machine Manager 2008, and then click Windows PowerShell – Virtual Machine Manager.

  2. At the command prompt, type the following commands, and then view the results:

    $VmmIsoObject1 = Get-ISO -VMMserver | where { $_.Name -eq "VMAdditions.iso" -and $_.LibraryServer.Name -eq "" }
    $VmmIsoObject2 = Get-ISO -VMMserver | where { $_.Name -eq "VMAdditions.iso" -and $_.LibraryServer.Name -eq "" }
    Set-ISO -ISO $VmmIsoObject2 -Name "VMAdditions-RTM.iso"
    $VmmIsoObject1 | format-list -property Name
    $VmmIsoObject2 | format-list -property Name
  3. Confirm that the name that is displayed for the $VmmIsoObject1 and $VmmIsoObject2 variables is VMAdditions-RTM.iso.

The commands in the example perform the following tasks:

  • The first command retrieves the object that represents the VMAdditions.iso file on LibServ01 from the library catalog in the VMM database. The command stores the ISO object in the $VmmIsoObject1 variable.

  • The second command retrieves the same object and then stores it in the $VmmIsoObject2 variable. A different server administrator who is working on a different computer might retrieve and store the object.

  • The third command changes the name of the object that is stored in $VmmIsoObject2 to VMAdditions-RTM.

  • The last two commands display the Name property of the objects that are stored in the $VmmIsoObject1 and $VmmIsoObject2 variables. Because VMM objects are synchronized, the name of the object in each variable has been changed to VMAdditions-RTM.iso.

See Also