How can we take user inputs in azure runbooks using powershell? does It supports user interaction?

392 views Asked by At

I have a PS script that register's an app in Azure AD. I want to add redirect URLs using ps script. I tried to take user inputs like,

$uri = Read-Host -Prompt "enter URI"

but this didn't work and threw the following error.

I have no clue what would be the solution for it.

error log=

RunbookFlow : 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: at System.Management.Automation.Internal.Host.InternalHostUserInterface.ThrowPromptNotInteractive(String promptMessage) at System.Management.Automation.Internal.Host.InternalHostUserInterface.Prompt(String caption, String message, Collection1 descriptions) at Microsoft.PowerShell.Commands.ReadHostCommand.BeginProcessing() at System.Management.Automation.Cmdlet.DoBeginProcessing() at System.Management.Automation.CommandProcessorBase.DoBegin() At line:6 char:57 + <#-- Enable activity tracing to see error location --#> RunbookFlow + ~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Orchestrator.GraphRunbook.Cmdlets.InvokeRunbookFlowCommand

1

There are 1 answers

0
Jahnavi On

Adding to @SwathiDhanwada comment & As explained in this Azure Document, runbook doesn't support interactive operations.

The "Read-Host -prompt" command requires user input. When you run this, it will interrupt the flow and attempt to enter the console mode for user interaction. User interactive operations does not support in Runbooks. As a result, we couldn't use it in the runbook.

Input and output parameters can be defined using a graphical PowerShell runbook if you want to consider giving it.

enter image description here

I tried prompting in Azure PowerShell and was able to receive prompt as shown:

read-host -prompt "xxx"

enter image description here

Note: To invoke read-host in Azure PowerShell, the App needs to be registered under Azure Active Directory -> App registrations. Now enable API Permissions to read the directory operations to avoid conflicts.

enter image description here