I am using the below code to create a new-csonlinesession in order to add new PSTN gateway.I am trying to setup new session and try to create new pstn usage:
public static void ExecuteSynchronously()
{
using (PowerShell PowerShellInstance = PowerShell.Create())
{
// use "AddScript" to add the contents of a script file to the end of the execution pipeline.
// use "AddCommand" to add individual commands/cmdlets to the end of the execution pipeline.
// PowerShellInstance.AddScript("param($param1) $d = get-date; $s = 'test string value'; " +
//"$d; $s; $param1; get-service");
// invoke execution on the pipeline (collecting output)
Collection<PSObject> PSOutput = PowerShellInstance.Invoke();
// check the other output streams (for example, the error stream)
if (PowerShellInstance.Streams.Error.Count > 0)
{
// error records were written to the error stream.
// do something with the items found.
}
// loop through each output object item
foreach (PSObject outputItem in PSOutput)
{
// if null object was dumped to the pipeline during the script then a null
// object may be present here. check for null to prevent potential NRE.
if (outputItem != null)
{
//TODO: do something with the output item
Console.WriteLine(outputItem.BaseObject.GetType().FullName);
Console.WriteLine(outputItem.BaseObject.ToString() + "\n");
}
}
}
}
Powershell code is working as expected.But getting error in c#.
I am getting "System.Management.Automation" "Could not find WWW-Authenticate header in response" error ?