Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure Can';t获取runbook测试(在门户中)以请求输入参数_Azure_Powershell_Azure Automation - Fatal编程技术网

Azure Can';t获取runbook测试(在门户中)以请求输入参数

Azure Can';t获取runbook测试(在门户中)以请求输入参数,azure,powershell,azure-automation,Azure,Powershell,Azure Automation,我是自动化的新手,正在尝试使用runbook连接到sql数据库并运行存储过程。问题是,我正在使用(改编自)的代码在我尝试测试它时没有要求服务器和凭据参数。测试窗口显示“无输入参数” 以下是我的(通用化)代码: 我在自动化帐户中存储了一些凭据,但我无法让测试实际请求它们!当我测试时,它会说“没有输入参数”。我有什么地方做错了吗?它会说没有输入参数,因为您没有正确地提供runbook所需的输入凭据。您必须使用Get-AutomationPSCredential cmdlet来实现这一点。我还没有做端

我是自动化的新手,正在尝试使用runbook连接到sql数据库并运行存储过程。问题是,我正在使用(改编自)的代码在我尝试测试它时没有要求服务器和凭据参数。测试窗口显示“无输入参数”

以下是我的(通用化)代码:


我在自动化帐户中存储了一些凭据,但我无法让测试实际请求它们!当我测试时,它会说“没有输入参数”。我有什么地方做错了吗?

它会说没有输入参数,因为您没有正确地提供runbook所需的输入凭据。您必须使用Get-AutomationPSCredential cmdlet来实现这一点。我还没有做端到端的测试,但很可能您可以按照链接来完成您的需求


希望这有帮助

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


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

如果您只运行内联脚本,那么工作流有什么意义?另外,我不认为强制参数可以有默认值。我还相当肯定,您没有以适当的方式检索凭据:一旦我让它工作起来,我计划将其列入日程。运行手册显然是Azure对SQL代理的回答。感谢您的回复,并对延迟表示抱歉。下面是我添加凭据的方式:在Azure门户中的自动化帐户中,我转到“共享资源”下的“凭据”。转到“添加凭据”,为其命名为“myDatabase Automation”,并输入用户名和密码。名字叫什么重要吗?这就是问题所在吗?除此之外,没有多少空间可以搞砸。
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()        
    }    
}