Azure Powershell工作流-找不到输入参数

Nic*_*dke 4 powershell azure azure-powershell

背景

我有一个使用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()
}
}
Run Code Online (Sandbox Code Playgroud)

问题

当我去测试工作流或运行它时,我并没有提示输入任何参数。 没有输入参数

Zuc*_*ini 6

尝试像这样将参数放在顶部。适用于我的Runbook。

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
    ...
}
Run Code Online (Sandbox Code Playgroud)

  • 嗯,现在我了解更多了。如果创建类型为“ powershell”的Runbook,它将不会作为工作流运行。这似乎是参数无法在工作流部分中起作用的原因。如果创建Powershell Workflow类型的运行手册,则可以在工作流程部分中包含参数,并且该参数有效(至少对我而言) (3认同)