I am trying to do a basic database operation using azure runbook (Code below). It is failing when I test it on Azure cloud. Error -
By doing a line by line execution, I found out that this error is caused by Get-AutomationPSCredential
. However, the entire code is working fine when I run it from PowerShell ISE in my local system.
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? 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.