Azure PowerShell module basics - Time & Space Complexity
We want to understand how the time to run Azure PowerShell commands changes as we do more work.
Specifically, how does running commands repeatedly affect the total time?
Analyze the time complexity of the following operation sequence.
# Connect to Azure account
Connect-AzAccount
# List all resource groups
Get-AzResourceGroup
# Create multiple resource groups in a loop
for ($i = 1; $i -le $n; $i++) {
New-AzResourceGroup -Name "rg$i" -Location "eastus"
}
This sequence connects to Azure, lists resource groups, then creates n new resource groups one by one.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Creating a resource group with
New-AzResourceGroup. - How many times: This operation runs once for each resource group, so n times.
Each new resource group requires a separate call to Azure, so the total time grows as we add more groups.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 calls to create resource groups |
| 100 | 100 calls to create resource groups |
| 1000 | 1000 calls to create resource groups |
Pattern observation: The number of calls grows directly with n, so doubling n doubles the calls.
Time Complexity: O(n)
This means the total time increases in direct proportion to the number of resource groups created.
[X] Wrong: "Creating multiple resource groups happens all at once, so time stays the same no matter how many groups."
[OK] Correct: Each creation is a separate call to Azure and takes time, so more groups mean more total time.
Understanding how repeated cloud commands add up helps you plan and explain automation tasks clearly.
"What if we created all resource groups using a single batch command instead of a loop? How would the time complexity change?"