Reputation: 185
I'm trying to convert an Azure PowerShell script to an Azure Automation Runbook, but I've run into an issue when using the "start-job" command. After the inline scripts are called, the jobs fail shortly after starting. It seems to me that the parameters are not passing through properly.
Is there something I'm missing to properly pass parameters within Azure Automation?
The commands that are failing:
$CreatevNetGateway = {
param($vNetName)
New-AzureVNetGateway -VNetName $vNetName -GatewayType DynamicRouting
}
<#Start the jobs#>
Start-Job $CreatevNetGateway -ArgumentList $vNetName1
Start-Job $CreatevNetGateway -ArgumentList $vNetName2
Wait-Job *
Upvotes: 0
Views: 3252
Reputation: 2540
In PowerShell Workflow, when you pass a value into an InlineScript block, you need to add $using to the front of the value. Ex:
workflow foo {
$message = "hi"
InlineScript {
Write-Output -InputObject $using:message
}
}
In addition, starting other jobs within the Azure Automation sandbox is not supported. It looks like you are trying to run two tasks in parallel and then do something only after both complete. PowerShell Workflow (the language / engine Azure Automation runbooks run on) has the parallel keyword that can be used for this:
workflow bar {
parallel {
New-AzureVNetGateway -VNetName $vNetName1 -GatewayType DynamicRouting
New-AzureVNetGateway -VNetName $vNetName2 -GatewayType DynamicRouting
}
# do something that happens after both of those complete
}
Upvotes: 0
Reputation: 10011
Try this:
$CreatevNetGateway = {
New-AzureVNetGateway -VNetName $args[0] -GatewayType DynamicRouting
}
<#Start the jobs#>
Start-Job $CreatevNetGateway -ArgumentList @($vNetName1)
Start-Job $CreatevNetGateway -ArgumentList @($vNetName2)
Get-Job | Wait-Job
Get-Job | Receive-Job
Upvotes: 0