Thanks for your insights, @Stanislav Zhelyazkov .
@Asperia ,
Great analysis! and thanks for the detailed steps provided! This looks like a feature gap so if interested, I would recommend you to raise this as a feature request in this UserVoice or feedback forum and also recommend you to upvote it and other features that are of interest. In general, Azure product / feature team would check feasibility of a feature request, triage it, prioritize against existing feature backlog, add in roadmap as appropriate and would announce and/or update the related Azure document once a feature request is addressed.
On the other hand, I don’t have a handy setup with multiple subscriptions to quickly test this out, but see if the below explained approach works as a workaround.
As described here, try to leverage child runbook so create 2 runbooks i.e., one parent and one child where parent runbook has foreach -parallel block and calls the child runbook using Start-AzAutomationRunbook cmdlet as shown below. And then child runbook does get the count of number of VM’s.
Parent runbook sample:
workflow PSWF1
{
#...
#Add your automation connection code here
#...
$subscriptionList = @('xxxxxxxxxxxxxxxxxxxxxxxxxxxxx','yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy')
$ChildRunbookInputParams = @{"SubscriptionId"="$($sub.SubscriptionId)"}
" With -Parallel"
foreach -Parallel ($subscription in $subscriptionList) {
$job = Start-AzAutomationRunbook -Name "PSWF1ChildRunbook" -Parameters @{"SubscriptionId"="$subscription"} -ResourceGroupName "<AutomationAccountResourceGroupName>" -AutomationAccountName "<AutomationAccountName>"
}
}
Child runbook sample:
workflow PSWF1ChildRunbook
{
Param
(
[Parameter (Mandatory= $true)]
[String] $SubscriptionId
)
#...
#Add your automation connection code here
#...
$SubscriptionContext = Set-AzContext -Subscription $SubscriptionId
"Total VMs $((Get-AzVM -AzContext $SubscriptionContext).Count)"
}
On publishing both the runbooks and then running the parent runbook, it should trigger two separate jobs for your two subscriptions under the child runbook.