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());
}
}
Hi Daithi,
Have you looked into using the .net assemblies directly from within C#? For example: https://stackoverflow.com/a/5493969
Can you run a regular PowerShell cmdlet in your setup?
For example Get-Process.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc, Yes I am able to get Powershell commands working. I.E dir C:\ or Get-Process which displays the results to the TextArea.
I'm definitely not a C# specialist, but why are you using the pipeline symbol (|) between the commands instead of the semi-column (;)?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Daithi,
Have you looked into using the .net assemblies directly from within C#? For example: https://stackoverflow.com/a/5493969