6

Background

I have a workflow defined using a straightforward template from within Azure.

workflow Use-SqlCommandSample
{
param(
    [parameter(Mandatory=$True)]
    [string] $SqlServer,

    [parameter(Mandatory=$False)]
    [int] $SqlServerPort = 1433,

    [parameter(Mandatory=$True)]
    [string] $Database,

    [parameter(Mandatory=$True)]
    [string] $Table,

    [parameter(Mandatory=$True)]
    [PSCredential] $SqlCredential
)

# Get the username and password from the SQL Credential
$SqlUsername = $SqlCredential.UserName
$SqlPass = $SqlCredential.GetNetworkCredential().Password

inlinescript {
    # Define the connection to the SQL Database
    $Conn = New-Object System.Data.SqlClient.SqlConnection("Server=tcp:$using:SqlServer,$using:SqlServerPort;Database=$using:Database;User ID=$using:SqlUsername;Password=$using:SqlPass;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;")

    # Open the SQL connection
    $Conn.Open()

    # Define the SQL command to run. In this case we are getting the number of rows in the table
    $Cmd=new-object system.Data.SqlClient.SqlCommand("SELECT COUNT(*) from dbo.$using:Table", $Conn)
    $Cmd.CommandTimeout=120

    # Execute the SQL command
    $Ds=New-Object system.Data.DataSet
    $Da=New-Object system.Data.SqlClient.SqlDataAdapter($Cmd)
    [void]$Da.fill($Ds)

    # Output the count
    $Ds.Tables.Column1

    # Close the SQL connection
    $Conn.Close()
}
}

Issue

When I go to either test the workflow or run it, I'm not prompting for any input parameters. No input parameters

1
  • try saving the runbook and go to test again, also try saving the runbook and accessing the test using another browser and\or another PC\incognito mode. Commented May 12, 2017 at 19:25

1 Answer 1

11

Try putting your parameters at the top like this. Works for my runbooks.

param(
    [parameter(Mandatory=$True)]
    [string] $SqlServer,

    [parameter(Mandatory=$False)]
    [int] $SqlServerPort = 1433,

    [parameter(Mandatory=$True)]
    [string] $Database,

    [parameter(Mandatory=$True)]
    [string] $Table,

    [parameter(Mandatory=$True)]
    [PSCredential] $SqlCredential
)

workflow Use-SqlCommandSample
{
    # Get the username and password from the SQL Credential
    $SqlUsername = $SqlCredential.UserName
    $SqlPass = $SqlCredential.GetNetworkCredential().Password
    ...
}
Sign up to request clarification or add additional context in comments.

2 Comments

It's just amazing that all Microsoft documentation examples have parameters defined within the workflow section! It doesn't work, but having them outside of the workflow section works just fine...
ah, now I understand more of it. If you create a runbook of type "powershell" it won't run as a workflow. That seems like the reason why parameters won't work inside the workflow section. If you create a runbook of type Powershell Workflow, you can have the parameters inside the workflow section and it works (at least for me)

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.