RobVious RobVious - 3 months ago 39
PowerShell Question

Capturing user input from a powershell workflow

I have the following:

Workflow Test {
$message = "Hey"
InlineScript{
Write-Output $using:message
Read-Host 'Get user input before proceeding.'
}
InlineScript{
Write-Output $using:message
}
}

Test


What I get in return:


A command that prompts the user failed because the host program or the
command type does not support user interaction.


Is there any way to tell a workflow to pause for user input before proceeding? I'm using Workflows to support parallel foreach - but I want to pause between operations.

I could try this:

Workflow Test1 {
$message = "Hey"
InlineScript{
Write-Output $using:message
Read-Host 'Get user input before proceeding.'
}
}

Workflow Test2 {
$message = "Hey"
InlineScript{
Write-Output $using:message
}
}

Test1
// wait for user input
Test2


But then I have repeated constants there -
$message
- which isn't very DRY.

Answer

A PowerShell Workflow is designed to run without interaction. Each workflow is scheduled as a job that runs in a seperate PowerShell instance.

Workflows are designed to be robust and parallel, and allowing input from a person in the middle of a workflow would increase the risk of something going wrong in the middle of execution.

You can pass parameters into a workflow by using the normal param keyword, which would allow you to get any information you need to execute the workflow up front.

workflow DoStuff
{
    param([string[]]$Value)

    ...
}

Another way to not require interactivity would be think about how you could detect when PowerShell should move on to the next operation instead of requiring a person to.