I am trying to enable IIS using Poweshell SDK in C sharp . My code is as follows.
using (PowerShell PowerShellInst = PowerShell.Create())
{
PowerShellInst.AddScript("Set-ExecutionPolicy Bypass -Scope Process; Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole");
Collection<PSObject> PSOutput = PowerShellInst.Invoke();
if (PowerShellInst.HadErrors)
{
foreach (var error in PowerShellInst.Streams.Error)
{
Console.WriteLine(error.ToString());
}
}
else
{
foreach (PSObject obj in PSOutput)
{
if (obj != null)
{
Console.Write(obj);
}
}
}
PowerShellInst.Stop();
}
}
Output is
Microsoft.Dism.Commands.ImageObject
When I execute same command using powershell then output is as follows
Is there a way to get output like this?
Note: google cloud shell when installing or upgrading on windows via command line shows such output.
question from:
https://stackoverflow.com/questions/65650340/enable-iis-using-powershell-sdk-and-c-sharp 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…