title: Hyper-V Get-VM in powershell via asp.net c#
body: <p>I am trying to write a web interface that will show the current VMs on a remote Hyper-V host.</p>
  
  <p>So far, I have this</p>
  
  <pre><code>    protected void getVMS(object sender, GridViewCommandEventArgs e)
      {
          //command to run
          string cmdToRun = "get-vm -computername fsyovs02";
  
          var shell = PowerShell.Create();
  
          shell.Commands.AddScript(cmdToRun);
  
          var results = shell.Invoke();
  
             if (results.Count &gt; 0)
             {
  
                var builder = new StringBuilder();
  
                foreach (PSObject vm in results)
                {
  
                    builder.Append(vm.BaseObject.ToString() + "\r\n");
                }
  
              ResultBox.Text = Server.HtmlEncode(builder.ToString());
            }
      }
  </code></pre>
  
  <p>This is returning something, but not what I want.  For each VM, it is returning the line </p>
  
  <pre><code>  Microsoft.HyperV.PowerShell.VirtualMachine
  </code></pre>
  
  <p>What I want is it to display exactly how it does via powershell.</p>
  
  <p>Can anyone help me please - as I am going out of my mind!</p>
  
  <p>Many Thanks
  Mark</p>