簡體   English   中英

無法在Azure自動化運行簿中獲取憑據

[英]Failed to get Credential in Azure Automation Runbook

我正在嘗試使用azure Runbook(下面的代碼)進行基本的數據庫操作。 當我在Azure雲上對其進行測試時,它失敗了。 錯誤- 在此處輸入圖片說明

通過逐行執行,我發現此錯誤是由Get-AutomationPSCredential引起的。 但是,當我從本地系統中的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

您能否讓我知道在創建憑據時是否錯過了任何內容,還是應該啟用任何配置以在Azure雲上測試此運行手冊? 預先感謝。 在此處輸入圖片說明

嘗試這個 :

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

您也可以檢查此鏈接: https : //docs.microsoft.com/zh-cn/azure/automation/automation-credentials

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM