Section 2: Azure Storage Accounts and Azure Virtual Machines
https://www.udemy.com/course/azure-powershell/learn/lecture/31092252?start=225#overview
20. Lab - Creating a resource group
To create a Resource Group in PowerShell (Azure), you typically use the Azure PowerShell module.
Step 1: Install & Import Azure PowerShell (if not already)
>>> Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
Import-Module Az
Step 2: Sign in to Azure
>>> Connect-AzAccount
Step 3: Create a Resource Group
>>> New-AzResourceGroup -Name "MyResourceGroup" -Location "EastUS"
Example with real values
>>> New-AzResourceGroup -Name "Dev-RG" -Location "CentralIndia"
Explanation
-
New-AzResourceGroup→ Creates a new resource group -
-Name→ Name of the resource group -
-Location→ Azure region (e.g., EastUS, CentralIndia, WestEurope)
Verify the Resource Group
>>> Get-AzResourceGroup -Name "Dev-RG"
This script went ahead and created the resource for us inspite of no authentication in our script. If you have already logged into your Azure account one way or the other -- The context of the authentication is embedded in your system . It is like caching your credentials and the same credentials are been used by your script file.
In order to have a realistic scenarios to ensure that Authentication or Authorization take place
Use the command
Disable-AzContextAutoSave -- Command
>>> Connect-AzAccount
We are going to create an Application Object inside Active Directory that will enable us to authenticate a user account.
Application Object creates a service principal at the background.
when you use a "Service Principal" you need to use the credential key word here the credential are mapped to the credential of our application object.
we need to convert the secret to a secure password though the password looks secure and complex The Credential use the AppId and the AppSecret
We has to add the Application object to our subscription to provide the permission to the Applicarion Object to access work on the subscription .
REMOVING RESOURCE GROUP
make sure you are in the correct subscription
>>> Get-AzContext
or set it:
>>> Set-AzContext -SubscriptionId "your-subscription-id"
To remove (delete) a Resource Group in Azure using PowerShell, you use the Az module.
>>> Remove-AzResourceGroup -Name "MyResourceGroup"
>>> Remove-AzResourceGroup -Name "Dev-RG"
Skip Confirmation Prompt
By default, PowerShell will ask for confirmation. To force delete:
>>> Remove-AzResourceGroup -Name "Dev-RG" -Force
🔹 Run as Background Job (optional)
If the resource group is large, deletion may take time:
>>> Remove-AzResourceGroup -Name "Dev-RG" -AsJob
Sometime you may want to save the output from this commands to use it in subsequent commands
Creating a Container
we can also use the "." operator
27. Understanding the scope of variables
30. Lab - Creating a File Share
35. Lab - Creating a Public IP Address
We also need to execute the network interface itself. we need to update the network interface with the new IPConfig and Public IP Address.
36. Lab - Creating a Network Security Group
37. Lab - Creating the Azure Virtual Machine
Creating a VM
39. Importance of arrays and objects
securepassword
44. Lab - Stopping an Azure VM
if you don't want it to prompt us add -force flag to it
46. Lab - Deleting the Virtual Machine
47. Lab - Creating a Linux Virtual Machine




























Comments
Post a Comment