无法获得运行手册测试(在门户中)以询问输入参数

Can't get a runbook test (in portal) to ask for input parameters

我是自动化的新手,我正在尝试获取一本 运行 书籍以连接到 sql 数据库和 运行 存储过程。问题是,我正在使用的代码(改编自 https://azure.microsoft.com/en-us/blog/azure-automation-your-sql-agent-in-the-cloud/)在我尝试对其进行测试时并未要求提供服务器和凭据参数。测试 window 说,"No input parameters."

这是我的(通用化)代码:

workflow DB_DailyTasks 
{
    param
    (
        # Fully-qualified name of the Azure DB server 
        [parameter(Mandatory=$true)] 
        [string] $SqlServerName="mydb.database.windows.net",

        # Credentials for $SqlServerName stored as an Azure Automation credential asset
        # When using in the Azure Automation UI, please enter the name of the credential asset for the "Credential" parameter
        [parameter(Mandatory=$true)] 
        [PSCredential] $Credential
    )

    inlinescript
    {

        # Setup credentials   
        $ServerName = $Using:SqlServerName
        $UserId = $Using:Credential.UserName
        $Password = ($Using:Credential).GetNetworkCredential().Password

        # Execute the udp_Test procedure

        # Create connection for each individual database
        $DatabaseConnection = New-Object System.Data.SqlClient.SqlConnection
        $DatabaseCommand = New-Object System.Data.SqlClient.SqlCommand

        $DbName = "myDB"

        # Setup connection string for $DbName
        $DatabaseConnection.ConnectionString = "Server=$ServerName; Database=$DbName; User ID=$UserId; Password=$Password;"
        $DatabaseConnection.Open();

        # Create command for a specific database $DBName
        $DatabaseCommand.Connection = $DatabaseConnection

        Write-Output "Running udp_Test procedure"

        $DatabaseCommand.CommandText = "EXECUTE [dbo].[udp_Test]"
        $NonQueryResult = $DatabaseCommand.ExecuteNonQuery()

        # Close connection to $DbName
        $DatabaseConnection.Close()        
    }    
}

我在自动化帐户中存储了一些凭据,但我无法通过测试实际询问它们!当我测试时,它说,"No input parameters."我做错了什么吗?

它说没有输入参数,因为据我所知,您没有正确地为 Runbook 提供所需的输入凭据。您必须使用 Get-AutomationPSCredential cmdlet 来执行此操作。我没有进行端到端测试,但很可能您可以按照 this link 来完成您的要求。

希望对您有所帮助!

我不是 100% 确定这一点,因为我实际上选择删除参数并只使用硬编码的服务器名称和对凭据的硬编码引用(它永远不会改变) ).但是当我这样做时,我 运行 遇到了不同的问题,我在这里发布了这些问题: ...答案是代码正在声明工作流运行手册,而 Azure 中的运行手册是常规 Powershell 运行手册。 (直到现在我才意识到有区别)。但这导致代码实际上根本 运行 。一旦我删除了工作流定义和内联脚本块(只留下代码),并删除了 $using 并修复了其他一些东西,它就起作用了。

我的猜测是,因为脚本根本不是真正的 运行,所以它之前没有要求参数,如果我选择保留参数,然后删除工作流程定义和内联脚本块会解决这个问题。

您好,您需要在删除

后将其添加到脚本的顶部
workflow DB_DailyTasks 
{ 

inlinescript
{
<#
.SYNOPSIS
     ..

.DESCRIPTION
    ... 

.PARAMETER param1
    ...

.PARAMETER param2
    ...

.PARAMETER param3
    ... 
#>
```