PowerShell Efficiency


I am an Azure engineer and administrator that is trying to get on top of Azure PowerShell so that I can deploy and manage Azure resources using Infrastructure as Code. I know the basics of PowerShell, however, I would very much like to become an expert at the subject.

An example of this is deploying Azure resource groups, something fairly simple to do when trying to deploy a single group, but when deploying multiple groups I am struggling to write the code more efficiently.

Example Code:

New-AzSubscriptionDeployment -Name $DeploymentName -Location UKSouth -TemplateFile Location -TemplateParameterFile Location

If I wanted to create multiple resource groups I would just run this command twice but change the details in the ARM template, however, I wanted to know how to create multiple resource groups using a single PowerShell command if possible?

If someone could point me in the right direction I would be grateful.

Thank you.

Welcome to the forums.

Powershell is easily able to handle lists/arrays of elements with loops like about_foreach or Foreach-Object. That’s actually a very basic technique. If you’re not familiar with this you may restart learning the very basics of PowerShell first. That will save you from a lot of wasted time and frustration.

A - as I think - still good starting point would be this: Getting Started with PowerShell 3.0 (don’t worry if it’s not about the current version of PowerShell - the basics are still the same :wink: )

Regardless of that: When you post code please format it as code. Thanks in advance.
Here you can read how that works:

1 Like