title: Control Hyper-V VMs with Python
body: <p>im trying to write a control VMs on a HyperV Server using Python. I start with connecting to the server the HyperV server runs on:</p>
  
  <pre><code>connection = wmi.connect_server(server="servername", namespace=r"root\virtualization", user=r"username", password=r"password")
  wmiServerConnection = wmi.WMI(wmi=connection)
  </code></pre>
  
  <p>This gives me a <code>wmi</code> object for this connection. </p>
  
  <p>For stopping and starting a VM I can simply use:</p>
  
  <pre><code>#get the wmi object representing the VM
  vmSystem = wmiServerConnection.Msvm_ComputerSystem(ElementName="VmName")
  #send change request to vm
  vmSystem[0].RequestStateChange(3)
  </code></pre>
  
  <p>But before starting a VM I want to apply a certain snapshot. 
  The class Msvm_VirtualSystemManagementService provides a method - <code>ApplyVirtualSystemSnapshot</code>/<code>ApplyVirtualSystemSnapshotEx</code> - for this. It needs the <code>SnapshotSettingData</code> as a parameter and I thought I could get that one using the <code>GetSummaryInformation</code> method of the same class. MSDN says this method returns a <a href="http://msdn.microsoft.com/en-us/library/cc160706%28v=vs.85%29.aspx" rel="nofollow">Msvm_SummaryInformation</a> class.</p>
  
  <p>I call this function like this:</p>
  
  <pre><code>#get the wmi class object
  vmManagement = wmiServerConnection.Msvm_VirtualSystemManagementService()
  snapshotInfo = vmManagement[0].GetSummaryInformation([1,107])
  </code></pre>
  
  <p>This should give me the name and the snapshot information for all VMs on the HyperV server. But all I get is list of COM Objects. </p>
  
  <p>When I try to give a certain VM as parameter gotten from </p>
  
  <pre><code>vmSettings = wmiServerConnection.Msvm_VirtualSystemSettingData(ElementName="VmName")
  </code></pre>
  
  <p>like this </p>
  
  <pre><code>snapshotInfo = vmManagement[0].GetSummaryInformation([1,107], [vmSettings[0]])
  </code></pre>
  
  <p>it crashes.</p>
  
  <p>My questions:</p>
  
  <ol>
  <li><p>Why don't I get a WMI object?</p></li>
  <li><p>The second parameter is obviously wrong. MSDN says it needs <code>CIM_VirtualSystemSettingData REF SettingData[]</code> as parameter. Is the WMI object the wrong one? How do I get the correct parameter?</p></li>
  <li><p>How can I retrieve the information I need from the COM object?</p></li>
  </ol>
  
  <p>Or am I totally on the wrong track?</p>
  
  <p>Thanks, Stefanie</p>