简体   繁体   English

无法在Azure自动化运行簿中获取凭据

[英]Failed to get Credential in Azure Automation Runbook

I am trying to do a basic database operation using azure runbook (Code below). 我正在尝试使用azure Runbook(下面的代码)进行基本的数据库操作。 It is failing when I test it on Azure cloud. 当我在Azure云上对其进行测试时,它失败了。 Error - 错误- 在此处输入图片说明

By doing a line by line execution, I found out that this error is caused by Get-AutomationPSCredential . 通过逐行执行,我发现此错误是由Get-AutomationPSCredential引起的。 However, the entire code is working fine when I run it from PowerShell ISE in my local system. 但是,当我从本地系统中的PowerShell ISE运行它时,整个代码运行良好。

workflow sqlrunbook()
{
    $SqlServer = "devserver001.database.windows.net"
    $Database = "devdb001"

    $SqlCredential = Get-AutomationPSCredential -Name 'SqlCredentialAsset'

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

    inlinescript
    {        
        $Conn = New-Object System.Data.SqlClient.SqlConnection("Server=tcp:$using:SqlServer;Database=$using:Database;User ID=$using:SqlUsername;Password=$using:SqlPassword;")

        $Cmd = New-Object System.Data.SqlClient.SqlCommand("insert into TestTable(ID) values(1)", $Conn)

        $Cmd.CommandTimeout=120

        $Conn.Open()        
        $Cmd.ExecuteNonQuery()
        $Conn.Close()
    }
}
sqlrunbook

Can you please let me know if I missed anyting while creating credential or should I enable any configuration to test this run book on Azure cloud? 您能否让我知道在创建凭据时是否错过了任何内容,还是应该启用任何配置以在Azure云上测试此运行手册? Thank in advance. 预先感谢。 在此处输入图片说明

try this : 尝试这个 :

Get-AzureAutomationCredential -AutomationAccountName "Contoso17" -Name "MyCredential"

you can check this link also: https://docs.microsoft.com/en-us/azure/automation/automation-credentials 您也可以检查此链接: https : //docs.microsoft.com/zh-cn/azure/automation/automation-credentials

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM