How to Get a List of Virtual Machines

 

Applies To: System Center 2016 - Service Provider Foundation, System Center Technical Preview

You can obtain a list of virtual machines by working with the VirtualMachines collection from the Virtual Machine Manager service (VMM service) in Service Provider Foundation.

To get a list of virtual machines

  1. Connect to the VMM service.

  2. Use the VirtualMachines collection property to get a list of virtual machines.

Example

The following code example retrieves all virtual machines from a specific stamp by using a lambda expression or a LINQ query expression.

  
SpfVMM.VMM vmmService = new SpfVMM.VMM(new Uri("https://wapserver:30006/97FD50F3-1DC0-41B6-A7C0-2B4FF4C3F7E3/services/systemcenter/vmm/"));  
  
Guid stampId = new Guid("62107714-182b-4f90-a3d1-97f5c6fd084e");  
  
List<SpfVMM.VirtualMachine> virtualMachines;  
  
virtualMachines = vmmService.VirtualMachines.Where(v => v.StampId == stampId).ToList();  
  
// - or -  
  
virtualMachines = (from v in vmmService.VirtualMachines  
                   where v.StampId == stampId  
                   select v).ToList();  
  

Compiling the Code

Assemblies

System
System.Core

Namespaces

System
System.Linq

See Also

Virtual Machine Management
Programming in Visual Studio with Service Provider Foundation Services
How to Create a Virtual Machine from a Template
How to Create a Virtual Machine from a VHD
How to Delete a Virtual Machine
How to Start and Stop Virtual Machines