Automation account parallel run invoke-sqlcmd

sakuraime 2,321 Reputation points
2021-02-22T06:55:43.867+00:00

I have a child runbook like in the following

Param  
     (  
     [String] $dblist  
)  
  
invoke-sqlcmd -ServerInstance "xxxxxxxxx.database.windows.net" -Database $dblist -Credential $SQLServerCred -Query "$getstatsQuery" -Encrypt  |format-table| Out-file $LogFull -width 400  

and another parent runbook

<#   
	This PowerShell script was automatically converted to PowerShell Workflow so it can be run as a runbook.  
	Specific changes that have been made are marked with a comment starting with “Converter:”  
#>  
workflow sqlmain {  
	# Ensure that the runbook does not inherit an AzContext  
    Disable-AzContextAutosave –Scope Process  
  
    # Connect to Azure with Run As account  
    $ServicePrincipalConnection = Get-AutomationConnection -Name 'AzureRunAsConnection'  
  
    Connect-AzAccount `  
        -ServicePrincipal `  
        -Tenant $ServicePrincipalConnection.TenantId `  
        -ApplicationId $ServicePrincipalConnection.ApplicationId `  
        -CertificateThumbprint $ServicePrincipalConnection.CertificateThumbprint  
  
    $AzureContext = Set-AzContext -SubscriptionId $ServicePrincipalConnection.SubscriptionID  
  
	# Converter: Wrapping initial script in an InlineScript activity, and passing any parameters for use within the InlineScript  
	# Converter: If you want this InlineScript to execute on another host rather than the Automation worker, simply add some combination of -PSComputerName, -PSCredential, -PSConnectionURI, or other workflow common parameters (http://technet.microsoft.com/en-us/library/jj129719.aspx) as parameters of the InlineScript  
	$dblist2= "mydb"  
    foreach -parallel ($db in $dblist2){  
  #  inlineScript {  
		Start-AzAutomationRunbook -ResourceGroupName "xxxxxx" -AutomationAccountName "xxxxxx" -Name "xxxxxx" -Parameters @{"dblist"=$db}   
		  
	}  
  #  }  
}  

but the parameter input to the childrunbook is

70519-capture.jpg

why is that?

Azure SQL Database
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,188 questions
{count} votes

1 answer

Sort by: Most helpful
  1. sakuraime 2,321 Reputation points
    2021-02-23T08:28:55.257+00:00

    finally got what's the problem

    Start-AzAutomationRunbook -ResourceGroupName "xxxxxx" -AutomationAccountName "xxxxxx" -Name "xxxxxx" -Parameters @{"dblist"="$db"}

    need to quote the $db too...

    1 person found this answer helpful.
    0 comments No comments