I am trying to get the list of virtual machine names, from a local Hyper-V server, with the following code:
string _scr = ("Get-VM | Select -ExpandProperty Name");
var _ps = PowerShell.Create();
_ps.AddScript(_scr);
Collection<PSObject> _cObj = _ps.Invoke();
foreach (PSObject _vm in _cObj)
{
Console.WriteLine(_vm);
}
The Get-VM cmdlet should return values in string format already, but I don't get any output.
I would like to get a result like the following output we get in PowerShell:
PS C:\> Get-VM | Select -ExpandProperty Name
VM-Name1
VM-Name2
VM-Name3
VM-Name4
PS C:\>
Can anyone help me with this please?
Thanks a million.
Ada