Azure: Powershell Workflows, speeding things up in azure! (and in AzureStack)

Here's a small snippet you can use in multiple ways to bulk create / modify / etc. do stuff against the azure API's in parallel. 

The Example below is used against deleting all the resource groups in my subscription. (operation 'Green Field', ;) )

So let me give a little bit of context. When you're working in Azure you will notice doing things in a traditional sense means sequential working. Due to the inner workings of the API.  So instead of sending a job of 10 items i will send 10 times 1 item as separate posts to the API in azure. They will all be handled at once saving me the time of waiting forever....But be warned there is a limit to doing things simultaneously! so be smart about  this because if you lock up the API with bulk posts you could block other users due to the limit set by Microsoft.

#Login to Azure to get the profile context ready.
Login-AzureRmAccount

#Fixed path for writing the profile to.
$path = 'c:\temp\AzureRmContext.json' 

#Save the profile to disk.
Save-AzureRmContext -Path $path -Force

#grabbing the resourcegroups from the subscription
$resourcegroups = Get-AzureRmResourceGroup

Workflow bulkremove-AzureRMResourceGroups 
    {
    Param (
    [parameter(Mandatory=$true)]
    [psobject]$ProfilePath,
    [parameter(Mandatory=$true)]
    [psobject]$ResourceGroups
    )
foreach -parallel ($ResourceGroup in $ResourceGroups)
            
            {
            $Profile =  import-AzureRmContext -Path $ProfilePath
            Write-Output "[[[ Removing ResourceGroup ]]] FOR $($resourcegroup.ResourceGroupName)..." 
            Remove-AzureRmResourceGroup -Name $resourcegroup.ResourceGroupName -Confirm:$false -Force
            }
    }

Reacties

Populaire posts van deze blog

One ADFS to serve them all (Part I)!

Microsoft Hub NVA configuration example.

RDS: Remote Desktop Gateway with NPS and Cross domain identities.