
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get Azure Resources from Resource Group Using PowerShell
To get the available resources from the resource groups using PowerShell, we need to use the Get-AZResource command. Suppose we have the resource group name AnsibleTestRG and we need to retrieve the resources from the resource group, then we will use the below command.
Example
Get-AzResource -ResourceGroupName AnsibleTestRG
To filter the output,
Output
Get-AzResource -ResourceGroupName AnsibleTestRG | Select Name, ResourceType, Location
Output
If there are multiple resource groups in the particular subscription, we can use the below commands to export the resources from the resource group to the CSV file.
Example
$ErrorActionPreference = "Stop" try { Connect-AZAccount Set-AzContext -SubscriptionName 'Your Subscription Name' $rgs = Get-AzResourceGroup foreach ($rg in $rgs.ResourceGroupName) { Write-Output "Checking Resource Group: $rg" Get-AzResource -ResourceGroupName $rg | Select Name, ResourceGroupName, Type, Location | Export-Csv .\AzureResources.csv -Append -Force -NoTypeInformation } } catch { Write-Host "$($_.Exception.Message)" -BackgroundColor DarkRed }
Advertisements