I have installed VMware PowerCLI inside ym application server, and if i directly write the following inside windows powershell i will get the resutl i am looking for :-
PS C:\Windows\system32> add-pssnapin VMware.VimAutomation.Core;
PS C:\Windows\system32> Connect-VIServer -Server ***** -User root -Password "*******"
PS C:\Windows\system32> Get-VMHOST
Name ConnectionState PowerState NumCpu CpuUsageMhz CpuTotalMhz MemoryUsageGB MemoryTotalGB Version
---- --------------- ---------- ------ ----------- ----------- ------------- ------------- -------
********** Connected PoweredOn 8 2733 18400 12.894 15.998 5.0.0
but if i try to run the command inside my asp.net mvc visual studio project , as follow:-
public ActionResult About(string vCenterIp = "****", string vCenterUsername = "****", string vCenterPassword = "****")
{
var shell = PowerShell.Create();
string PsCmd = "add-pssnapin VMware.VimAutomation.Core; $vCenterServer = '" + vCenterIp + "';$vCenterAdmin = '" + vCenterUsername + "' ;$vCenterPassword = '" + vCenterPassword + "';" + System.Environment.NewLine;
PsCmd = PsCmd + "$VIServer = Connect-VIServer -Server $vCenterServer -User $vCenterAdmin -Password $vCenterPassword;" + System.Environment.NewLine;
PsCmd = PsCmd + "$VMHosts = Get-VMHost" + System.Environment.NewLine;
shell.Commands.AddScript(PsCmd);
var results = shell.Invoke();
if (results.Count > 0)
then the result will always be zero .. can anyone adivce on this please?