PowerShell Script invoke issue from c# code and the test script execution is getting failed with an error

public void ExecuteUITest(string Workflow)
{
string filePath = $@“{CurrentWorkingDirectory}\StartUITests.ps1”;
RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
Command scriptCommand = new Command(filePath);
Collection commandParameters = new Collection();
CommandParameter commandParm = new CommandParameter(“Workflow”, Workflow);
commandParameters.Add(commandParm);
scriptCommand.Parameters.Add(commandParm);
pipeline.Commands.Add(scriptCommand);
pipeline.Invoke();
}

**Issue Details **
When trying to execute the above method (ExecuteUITest) with a value passed through the parameter “Workflow”, Iam able to reach the StartUITests.ps1 where this workflow value is passed as a parameter again to another solution and it executes the respective methods inside the class file based on the parameter value passed.
The issue here is its invoking the method based on the parameter name successfully and once the method execution is completed it returns with an error and the test script execution is getting failed

Error details
Error Message: System.Management.Automation.CmdletInvocationException : A command that prompts the user failed because the host program or the command type does not support user interaction. The host was attempting to request confirmation with the following message:
Data:
System.Management.Automation.Interpreter.InterpretedFrameInfo: System.Management.Automation.Interpreter.InterpretedFrameInfo
----> System.Management.Automation.Host.HostException : A command that prompts the user failed because the host program or the command type does not support user interaction. The host was attempting to request confirmation with the following message:
Stack Trace:
at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
at DcsPlus.ApiTests.BatchOMSConfig.Test.cs.test.BatchOMSConfigWorkflow.ExecuteUITest(String Workflow) in D:\Final\IuT_TA\src\APItests_Playground\DcsPlus.ApiTests.BatchOMSConfig.Test\BatchOMSConfigWorkf
low.cs:line 253
at DcsPlus.ApiTests.BatchOMSConfig.Test.cs.test.BatchOMSConfigWorkflow.BatchOMS_projectConfiguration() in D:\Final\IuT_TA\src\APItests_Playground\DcsPlus.ApiTests.BatchOMSConfig.Test\BatchOMSConfigWork
flow.cs:line 71
–HostException
at System.Management.Automation.Internal.Host.InternalHostUserInterface.ThrowPromptNotInteractive(String promptMessage)
at System.Management.Automation.Internal.Host.InternalHostUserInterface.Prompt(String caption, String message, Collection`1 descriptions)
at Microsoft.PowerShell.Commands.ReadHostCommand.BeginProcessing()
at System.Management.Automation.Cmdlet.DoBeginProcessing()
at System.Management.Automation.CommandProcessorBase.DoBegin()

Please let me know am I missing anything… immediate response is highly appreciated

Screenshot from StartUITests.ps1 file

OS : Windows Server 2019 Standard / 64 bit

Ashok,
Welcome to the forum. :wave:t3:

Before we proceed … please do not post images of code, console output or error messages as this is not helpful at all. Instead post the plain text and format it as code. This makes it easy for people willing to help you to actually copy your code and use it right away to reproduce your issue if needed.

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org 1 <---- Click :point_up_2:t4: :wink:

( !! Sometimes the preformatted text button hides behind the settings gear symbol. :wink: )

StartUITests.ps1 code :

param([string] $Workflow)
$TestDLL = "Test.UiTest.cs.Test.dll"
$TestChoice = "2"
$TestClass = $Workflow

& cd "D:\Final\IuT_TA\Binaries\Release\x64\UserTests\UITests\bin"
$vstest = "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"
$settings = "/Settings:D:\LocalSetting.runsettings"
$testAdapter = "/TestAdapterPath:D:\Skynet\Client\NUnit3TestAdapter"


if("" -eq $TestDLL -or "" -eq $TestChoice -or "" -eq $TestClass -or "" -eq $TestMethod) {

& $vstest Test.UiTest.BF.SmokeTest.cs.test.dll /TestCaseFilter:FullyQualifiedName~Test.UiTest.BF.Test.Tests.SmokeTestOnSingleStation $settings $testAdapter
} else {

switch ($TestChoice) {
1 {
& $vstest $TestDLL /TestCaseFilter:FullyQualifiedName~$TestClass $settings $testAdapter
}
2 {
& $vstest $TestDLL /TestCaseFilter:"Name=$TestClass" $settings $testAdapter
}
}
}
}
Pause

Invoke call from 1st solution:
Test Dll : Test.ApiTests.Config.Test.cs.test.dll

using NUnitExtensions.PropertyAttributes;
using NUnit.Framework;
using NUnitExtensions.CategoryAttributes;

namespace Test.Sample
{

[TestFixture]

public class BatchOMSConfigWorkflow
  
  {

public const string PROJECTCREATION_WORKFLOW = "DummyWorkflow";

 [TestCase(TestName = "Dummy Test")]

      [Test(Author = "Ashok Kumar"), TestCategories.Stability]

       public void Batch_projectConfiguration()
       {

            ExecuteUITest(PROJECTCREATION_WORKFLOW);
	}

     }

 }
*ExecuteUiTests Method which is invoked from 1st solution :*

public void ExecuteUITest(string Workflow)
{
string filePath = $@“{CurrentWorkingDirectory}\StartUITests.ps1”;
RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
Command scriptCommand = new Command(filePath);
Collection commandParameters = new Collection();
CommandParameter commandParm = new CommandParameter(“Workflow”, Workflow);
commandParameters.Add(commandParm);
scriptCommand.Parameters.Add(commandParm);
pipeline.Commands.Add(scriptCommand);
pipeline.Invoke();
}

Workflow - " DummyWorkflow" is passed as a parameter to another solution as an Method
Test Dll name : Test.UiTest.cs.Test.dll — 2nd Solution

using NUnitExtensions.PropertyAttributes;
using NUnit.Framework;
using NUnitExtensions.CategoryAttributes;

namespace Test.Sample2
{

[TestFixture]

public class BatchUIWorkflow
  
  {

 [TestCase(TestName = "Dummy Test")]

      [Test(Author = "Ashok Kumar"), TestCategories.Stability]

       public void DummyWorkflow()
       {

            Console.writeline("testing powershell script invoke");
	}

     }

 }