BlogPost

Azure - Manage Azure resources and resource groups by using Azure PowerShell - Part 2

Azure - Manage Azure resources and resource groups by using Azure PowerShell - Part 2



In today's post we are going to continue on from the previous post and manage Azure resources and resource groups using PowerShell



Step One

Download and open the following file UsingPowerShell.ps1 in the Windows PowerShell ISE window



Step Two

In the # Variables section, note the values of predefined variables. They need to match the names of resource and the resource group we created in the previous post to match your resource groups





Step Three

Under the line that states # Identify the location of the resource group containing the resource, type the following:

$locName = (Get-AzureRmResourceGroup -Name $rg1Name).Location

Select all of code in the file, including the line you just typed, right-click it, and then click Run selection.


Step Four

Under the line that states # Create a new resource group in the same location, type the following:

$rg2 = New-AzureRmResourceGroup -Name $rg2Name -Location $locName

Select the line you just typed, right-click it, and then click Run selection.


Step Five

Under the line that states # Retrieve an object representing the resource and store it in a variable, type the following:

$res = Get-AzureRmResource -ResourceName $resName -ResourceGroupName $rg1Name

Select the line you just typed, right-click it, and then click Run selection.


Step Six

Under the line that states # Move the resource to the new resource group, type the following:

Get-AzureRmResource | Where-Object ResourceGroupName -eq $rg2Name

Select the line you just typed, right-click it, and then click Run selection. When prompted to confirm, click Yes. Wait until the move operation completes.


Step Seven

Under the line that states # View resources in the new resource group, type the following:

$locName = (Get-AzureRmResourceGroup -Name $rg1Name).Location

Select the line you just typed, right-click it, and then click Run selection.





Verify that the route table was moved to the new resource group. Result:




Result: After completing this exercise, you should have used Azure PowerShell to manage Azure resources and resource groups.



In the next Series of posts we will use the Azure CLI