gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 09:54:01 25 4
gpt4 key购买 nike

背景

我使用 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()
}
}

问题

当我测试工作流程或运行它时,我不会提示输入任何输入参数。 No input parameters

最佳答案

尝试将您的参数像这样放在顶部。适用于我的操作手册。

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
...
}

关于powershell - Azure Powershell 工作流 - 未找到输入参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43944863/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com