title: Retrieving real time info from VM's with PowerCLI
body: <p>I have a couple of lines in a script that are giving me an issue:</p>
  
  <pre><code>Connect-VIServer "test-vcenter.test.com" -User user -Password pass
  Get-VM -Name "test-vm" | Get-Stat -Stat cpu.ready.summation -Realtime | Select-Object -First 1  value | Format-List
  </code></pre>
  
  <p>When running this I receive this as output:</p>
  
  <pre><code>Operation is not valid due to the current state of the object.
  At :line:0 char:0
  </code></pre>
  
  <p>If the second line is run a few seconds after the connection to vCenter is made I receive the output I expect. What I believe is happening is that my connection to vCenter hasn't completed before my second line has started. I am not sure of the best way to wait for or what to check for in a completed connection.</p>