How to give user input to custom powershell cmdlets from another project

Seeker

I have a separate test project to test my cmdlets project that has calls like :

pSCmdletObject.InvokeCommand.InvokeScript("Write-Host " + outputString); and
pSCmdletObject.InvokeCommand.InvokeScript("Read-Host");

I have used the PSHostUserInterface, PSRawUserInterface, PSHost implementation examples given in C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0\Samples\sysmgmt\WindowsPowerShell\csharp\Host03

Here is the problem :

TestClass.cs (of the Test project) :

using (Runspace runSpace = RunspaceFactory.CreateRunspace(new Host(new TestClass())))
{
    runSpace.Open();

    using (Pipeline pipeline = runSpace.CreatePipeline())
    {
        pipeline.Commands.Add("CustomCommand-Get");
        var output = pipeline.Invoke();   //<<< (1)
    }
}

At "(1)" when "Invoke" is called, the "CustomCommand" implementation written in the actual project is called. In the "CustomCommand"'s "ProcessRecord()" of the actual cmdlets project, when "Read-Host" is called, the project just waits for input which I currently can't provide because I am unable to find a way to that. My test project has the Invoke call and I want to avoid using the console. I want to somehow hard-code the inputs according to the test cases as the actual Custom Cmdlet project is an entirely different project that can run independently on its own. Can this be done? If so, how? Any other way to achieve this?

Thanks in advance

Keith Hill

If you have a custom host implementation then you can modify that host impl to create a test host impl where you can have PSHostUserInterface.Prompt() and PSHostUserInterface.ReadLine() return whatever you want when these methods are called. These methods (plus PSHostUserInterface.ReadLineAsSecureString()) are called by Read-Host to read a string from the host (end user).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to give input file from project folder in servlet

From Dev

How to give input values from user to a process run in a program

From Dev

How to call PowerShell cmdlets from C# in Visual Studio

From Dev

How to access user input from another method

From Dev

How to access user input from another method

From Dev

How to give user input in cronjob script

From Dev

How to reuse web user controls from another project in the solution?

From Dev

php -laravel How to Save custom data from user input

From Dev

How do i find a word from user input in another variable?

From Dev

How to access user input from an activity to another class?

From Dev

How to install Azure cmdlets using powershell

From Dev

How to install Azure cmdlets using powershell

From Dev

SQL PowerShell Cmdlets How to Install Server 2012

From Dev

Powershell Prompt For Input From Remote User

From Dev

Referencing user input string from another class?

From Dev

Pass user input (from TextField) to another class?

From Dev

How to give an error msg based on user input in my program?

From Dev

How do I give permissions to another user on firebase?

From Dev

How to give a particular use's privileges to another user in Debian?

From Java

How to replace a part of user input with another user input?

From Dev

How to make a powershell program restart on user input

From Dev

Powershell Parameters: How to read order of user input

From Dev

Cannot run PowerShell cluster cmdlets from a standalone server

From Dev

How to build project from another project in TeamCity?

From Dev

How utilize user input later in another method

From Dev

Is it possible to/how do you stop powershell using certain cmdlets?

From Dev

How to provide default value for a parameter in PowerShell help for compiled cmdlets

From Dev

Is it possible to/how do you stop powershell using certain cmdlets?

From Dev

Concatenating Multiple cmdlets in Powershell

Related Related

  1. 1

    how to give input file from project folder in servlet

  2. 2

    How to give input values from user to a process run in a program

  3. 3

    How to call PowerShell cmdlets from C# in Visual Studio

  4. 4

    How to access user input from another method

  5. 5

    How to access user input from another method

  6. 6

    How to give user input in cronjob script

  7. 7

    How to reuse web user controls from another project in the solution?

  8. 8

    php -laravel How to Save custom data from user input

  9. 9

    How do i find a word from user input in another variable?

  10. 10

    How to access user input from an activity to another class?

  11. 11

    How to install Azure cmdlets using powershell

  12. 12

    How to install Azure cmdlets using powershell

  13. 13

    SQL PowerShell Cmdlets How to Install Server 2012

  14. 14

    Powershell Prompt For Input From Remote User

  15. 15

    Referencing user input string from another class?

  16. 16

    Pass user input (from TextField) to another class?

  17. 17

    How to give an error msg based on user input in my program?

  18. 18

    How do I give permissions to another user on firebase?

  19. 19

    How to give a particular use's privileges to another user in Debian?

  20. 20

    How to replace a part of user input with another user input?

  21. 21

    How to make a powershell program restart on user input

  22. 22

    Powershell Parameters: How to read order of user input

  23. 23

    Cannot run PowerShell cluster cmdlets from a standalone server

  24. 24

    How to build project from another project in TeamCity?

  25. 25

    How utilize user input later in another method

  26. 26

    Is it possible to/how do you stop powershell using certain cmdlets?

  27. 27

    How to provide default value for a parameter in PowerShell help for compiled cmdlets

  28. 28

    Is it possible to/how do you stop powershell using certain cmdlets?

  29. 29

    Concatenating Multiple cmdlets in Powershell

HotTag

Archive