Azure 資源清單
- 作用
- 前置條件
- 安裝PowerShell 7.0+
- 驗證
- Azure資源清單安裝配置
- 如果有舊版本,導致新模塊安裝不上,進行強制安裝
- PowerShell 登錄到 Azure
- 基本命令
- 輸出詳細信息
- 效果圖展示
作用
官方文檔:https://github.com/microsoft/ARI?tab=readme-ov-file#-key-features
Azure 資源清單 (ARI) 是一個全面的 PowerShell 模塊,可生成你具有讀取訪問權限的任何 Azure 環境的詳細 Excel 報告。它專為需要一種簡單快速的方式來記錄其 Azure 環境的云管理員和技術專業人員而設計。
前置條件
- PowerShell 7.0+
- 對要清點的資源具有讀取訪問權限的 Azure 帳戶
- 腳本執行期間的管理員權限(用于模塊安裝)
安裝PowerShell 7.0+
官方文檔
https://github.com/PowerShell/PowerShell/releases/tag/v7.5.1
- 64位系統:PowerShell-7.5.1-win-x64.msi
- 32位系統:PowerShell-7.5.1-win-x86.msi
查看電腦屬性配置的系統類型下載對應powershell
安裝時勾選 Add ‘Open here’ context menu to Explorer(資源管理器右鍵菜單)
驗證
pwsh --version
Azure資源清單安裝配置
直接從 PowerShell 庫安裝模塊:
Install-Module -Name AzureResourceInventory
加載模塊
Import-Module AzureResourceInventory
如果有舊版本,導致新模塊安裝不上,進行強制安裝
保留舊版本強制安裝
Install-Module -Name AzureResourceInventory -Force -Scope CurrentUser
安裝后查看所有版本
Get-Module -Name AzureResourceInventory -ListAvailable | Select-Object Version
PowerShell 登錄到 Azure
登錄到中國區Azure
Connect-AzAccount -EnvironmentName AzureChinaCloud
國際區
Connect-AzAccount
PowerShell 登錄到 Azure后切換訂閱
Set-AzContext -Subscription 訂閱名
基本命令
使用特定租戶運行 ARI:
Invoke-ARI -TenantID <Azure-Tenant-ID>
特定訂閱的范圍:
Invoke-ARI -TenantID <Azure-Tenant-ID> -SubscriptionID <Subscription-ID>
在報表中包含資源標簽:
Invoke-ARI -TenantID <Azure-Tenant-ID> -IncludeTags
輸出詳細信息
- 默認輸出位置:
- windows:C:\AzureResourceInventory\
- Linux/CloudShell的:$HOME/AzureResourceInventory/
- 輸出文件名格式:AzureResourceInventory_Report_yyyy-MM-dd_HH_mm.xlsx
- 圖表文件名格式:(Draw.io 格式)AzureResourceInventory_Diagram_yyyy-MM-dd_HH_mm.xml
效果圖展示