0

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.

3
  • I'm fairly certain that this isn't possible. Workflows can be triggered "interactively" but are expected to be run non-interactive, and often against a number of different machines all at once. The reason you even need InlineScript to support all PowerShell commands is because it's a different environment, so you can think of those blocks as running in a different runspace. Commented Aug 10, 2016 at 20:33
  • @briantist - I see. I guess I could do separate workflows, but then I have to repeat all of my variable declarations in every single one, which seems really messy. Any tips on this? Updating question now. Commented Aug 10, 2016 at 20:50
  • If the only reason you're using a workflow is for parallelism, I'd recommend just using jobs or PoshRsJob. Commented Aug 10, 2016 at 20:51

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.