Hi there

If you’re like anybody else who likes to optimize your work trying to automate your LABs I hope this article might be helpful. Following you have a couple PowerShell commands to have your own lab ready to go.

Steps

1. Create your Free Azure Account – link

2. Install all required PowerShell modules on your PC (make sure you already have Powershell on your system)

Install-Module -Name Az -AllowClobber

OR you can log on Azure Portal and use the Azure Cloud Shell

Log on Azure portal https://portal.azure.com

Launch the Azure Cloud shell

3. Creating your “Demo1” Azure Resource Group on “CanadaCentral” location

New-AzResourceGroup -Name Demo1 -Location "canadacentral"

4. Creating your Storage account at “CanadaCentral” location with Standard_GRS SKUName

New-AzStorageAccount -ResourceGroupName Demo1 -AccountName mystorageaccount01001 -Location canadacentral -SkuName Standard_GRS

5. Adding tags to your Azure Resource Group (Tag Names: Dept and Environment with following values: IT and PROD)

$tags = @{"Dept"="IT"; "Environment"="PROD"}
$resourceGroup = Get-AzResourceGroup -Name Demo1
New-AzTag -ResourceId $resourceGroup.ResourceId -tag $tags

6. Adding tags to your Azure Resource items (Azure Resources)

$tags = @{"Dept"="IT"; "Environment"="PROD"}
Get-AzResource -ResourceGroupName Demo1 | foreach { 
Write-Host $_.ResourceName $_.Tags 
New-AzTag -ResourceId $_.ResourceId -Tag $_.Tags }

7. Clearing all Azure Resources’ tags (it only clears azure resources item’s tags.

#Clear all TAGS (that are not enforced by Azure Policy from a Azure Resource Item)
#This script doesn't clear azure policy enforced tags 
Get-AzResource -ResourceGroupName Demo1 | foreach {
Write-Host $_.ResourceName
$_.Tags
Update-AzTag -ResourceId $_.ResourceId -Tag $_.Tags -Operation Delete
}

You should have something similar to this

Now you have your first Azure Lab to play around #Enjoy it.

[Book Me]

thanks,

Thiago Beier
TwitterLinkedInFacebookRSS