Sometimes it's just better to load "all" the data

8 points by abnercoimbre


regulator

One of the first tasks I had in my current role was to fix an automation for pulling metadata from specific Azure VMs. The current process was a PowerShell script that ingested a spreadsheet containing one VM per line and then called "Get-AzVm" on each VM.

The spreadsheet would be hundreds or thousands of lines long, and with each Get-AzVm call taking about 3 seconds, the script would often take more than an hour to finish.

I inverted the process: Run Get-AzVm with no arguments to get every VM from the Subscription, build a hashmap of Name -> VM Object, then ingest the spreadsheet and use the names from the spreadsheet to get the relevant object out of the hashmap. It went from a few thousand calls to just one, so the script now takes 5~ seconds to run.