4 Replies Latest reply on Feb 11, 2020 7:48 PM by evilensky

    PowerCLI within APS.NET

    Daithi_N Lurker

      Hi,

       

      need some help with regards to calling powercli from the ASP.NET C#

      Even if i do a Get-VM nothing shows: p

       

       

       

              protected void Button1_Click(object sender, EventArgs e)
              {
                  var shell = PowerShell.Create();
                  string vmware = "";
                  string impcred = "C:\\user\\demo\\desktop\\demo.cred";
                  shell.Commands.AddScript("$creds = import-clixml -Path" + impcred + "| Connect-viserver -server" + vmware + "-Credential $creds | Remove-VM testimage -DeletePermanently | out-string");
                  var results = shell.Invoke();
                  if (results.Count > 0)
                  {
                      var builder = new StringBuilder();
                      foreach (var psObject in results)
                      {
                          builder.Append(psObject.BaseObject.ToString() + "\r\n");
                      }
                      ResultBox.Text = Server.HtmlEncode(builder.ToString());
                    
      }        
          }