Powershell
Powershell Basics
Provisioning can be done by using Azure CLI. Azure CLI can be executed using Powershell. The most commonly used Powershell scripts are:
Variables
Variables are declared using the '$' sign, like $resourceGroup.
Example:
$resourceGroup = "MyResourcegroup"
Arrays
Arrays can be declared to group multiple variables.
Example:
$environments = @('tst', 'uat', 'prd')
Multi Domensional Arrays
Array items can have mulitple values.
Example:
$environments = @(
@{
name = "Test"
prefix = 'tst'
},
@{
name = "Acceptance"
prefix = 'uat'
},
@{
name = "Production"
prefix = 'prd'
}
)
foreach ($env in $environments) {
Write-Host $env.name
}
Ouput:
tst
uat
prd
Loops
A loop is used to iterate over an array.
Example:
$environments = @('tst', 'uat', 'prd')
foreach($env in $environments){
Write-Host $env
}
Ouput:
tst
uat
prd
Functions
Commonly used Powershell functions:
String formatting
To format a string, you can use the '-f' flag to merge strings and variables.
Example:
$env = "tst"
$webapp = "{0}-azure-web-app" -f $env
Write-Host $webapp # this will result in "tst-azure-web-app"