g.pickardou
g.pickardou

Reputation: 35973

How to execute asynchronously or paralellize Azure PowerShell operations to spare time?

In my script there are 10 endpoint configuring operations for 10 endpoints in a row like this: (please note: I am completely new to Azure PoweShell, started using yesterday, however I am experienced developer)

Get-AzureVM –ServiceName myservice –Name myvm | 
    Add-AzureEndpoint –Name SqlEndpoint –Protocol tcp –LocalPort 1433 `
    –PublicPort 1433 –ACL $acl | 
    Update-AzureVM

Unfortunatelly one takes 10-15 seconds to be completed, and they are executed in a serialized way: the next one only starts when the previous finished, so the 10 operation takes 2 minutes.

I would be happy if I can it speed up things in some way. I Suppose this serialized way is not coming from the deep Azure nature (architecture) as we can imagine 10 clients connecting and issuing the 10 operations in the very same time to the server. (I strongly hope Azure will not queue them internally and executes them 10x15 seconds...)

Upvotes: 1

Views: 157

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 59031

Yes, you just call the Add-AzureEndpoint (or Set-AzureEndpoint) multiple times and invoke the Update-AzureVM cmdlet only once (at the end):

$vm = Get-AzureVM –ServiceName myservice –Name myvm  
Add-AzureEndpoint –Name SqlEndpoint –Protocol tcp –LocalPort 1433 –PublicPort 1433 –ACL $acl -vm $vm
Add-AzureEndpoint –Name Endpoint2 ...
Add-AzureEndpoint –Name Endpoint3 ...
...
$vm | Update-AzureVM 

Upvotes: 1

Related Questions