Hi,
I can't reproduce the problem.
And I don't see the product id of "Microsoft.AppHostQueryProcessor" is used by IIS Powershell on RTW (Go Live) build.
Are you using old version? Or, please try your program in a clean machine with the IIS Powershell RTW (Go Live) build.
I executed the below program and I did not see any error as the below screenshot:
C:\temp>ConsoleApplication2.exe
Name ID State Physical Path Bindings
---- -- ----- ------------- --------
Default Web Site 1 Started %SystemDrive%\inetpub\wwwroot http *:80:
FYI, here I am attaching the source files for the above program.
test.ps1 souce file:
### supposing the powershell execution policy is already set with remotesigned
Remove-PSSnapin webadministration
Add-PSSnapin webadministration
Get-WebSite
program.cs source file:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Collections.ObjectModel;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string cmdLine = @"c:\temp\test.ps1";
Console.WriteLine(Program.RunPSScript(cmdLine));
}
public static string RunPSScript(string scriptText)
{
// create Powershell runspace
PSConsoleLoadException warnings = new PSConsoleLoadException();
RunspaceConfiguration rsc = RunspaceConfiguration.Create();
Runspace runspace = RunspaceFactory.CreateRunspace(rsc);
// open it
runspace.Open();
// create a pipeline and feed it the script text
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(scriptText);
// add an extra command to transform the script
// output objects into nicely formatted strings
pipeline.Commands.Add("Out-String");
// execute the script
Collection<PSObject> results = pipeline.Invoke();
// close the runspace
runspace.Close();
// convert the script result into a single string
StringBuilder stringBuilder = new StringBuilder();
foreach (PSObject obj in results)
{
stringBuilder.AppendLine(obj.ToString());
}
return stringBuilder.ToString();
}
}
}
Thanks,
Jeong Hwan Kim