Azure Inventory Management with PowerShell

Listen – creating resources in Azure with PowerShell is easy – but actually knows what you have deployed is something else. Let’s dive into the steps to harness the power of PowerShell for a streamlined Azure inventory process.

Prerequisites

Before we embark on this journey, ensure you have:

  • An Azure account with necessary access permissions.
  • PowerShell and the Azure PowerShell module ready on your machine.

Configuring PowerShell for Azure

Connecting to Azure is the first step. Open your PowerShell window and enter these commands. This should let you set your context from the Gridview.

# Connect to Azure with interactive login
Connect-AzAccount

# List subscriptions and select one interactively
Get-AzSubscription | Out-GridView -PassThru | Set-AzContext

Lets go ahead and start to look at your resources:

# List all resources and export to CSV
Get-AzResource | Select-Object ResourceType, Name, Location | Export-Csv -Path ./AllResources.csv -NoTypeInformation

# VM Inventory: List VMs and export their details
Get-AzVM | Select-Object Name, Location, HardwareProfile.VmSize | Export-Csv -Path ./VMInventory.csv -NoTypeInformation

# Storage Accounts: List accounts and export their details
Get-AzStorageAccount | Select-Object StorageAccountName, Location, SkuName | Export-Csv -Path ./StorageAccounts.csv -NoTypeInformation

# Network Resources: List VNets and export their details
Get-AzVirtualNetwork | Select-Object Name, Location, AddressSpace | Export-Csv -Path ./VNetInventory.csv -NoTypeInformation

In the scripts above, each command not only fetches the necessary details but also exports them to a CSV file for easy access and reporting.

Advanced Techniques

Organizing and managing your resources effectively can further be achieved by using tags.

# Organizing resources with Tags: Filter by tag and export
Get-AzResource -Tag @{ Department="Finance"} | Select-Object Name, ResourceType | Export-Csv -Path ./FinanceResources.csv -NoTypeInformation

For more insights and advanced techniques, visit the Azure PowerShell documentation. Here’s to efficient management of your Azure resources. Happy scripting!