2
0

More than 3 years have passed since last update.

【Azure】サブスクリプション内の NSG ルール一覧を取得する Azure CLI

Last updated at Posted at 2021-05-12

サブスクリプション内のNSGルール一覧を取得する Azure CLI を考えたので、メモしておきます。

前提

  • 操作端末に Azure CLI をインストールしていること
  • サインインアカウントに Azure サブスクリプション内のNSG参照権限があること

コマンド

Get-NSG-rule-list.azcli
# Azure サインイン
az login

# サブスクリプション選択
azureSubscription={your subscription}
az account set --subscription $azureSubscription

# NSG 一覧確認
az network nsg list -o table

# NSGの名前とリソースグループ取得
nsgsName=($(az network nsg list -o tsv --query [].name))
nsgsRg=($(az network nsg list -o tsv --query [].resourceGroup))

# NSGルール一括取得
for((i=0; i<${#nsgsName[@]}; i++))
do
    echo "NSG name: ${nsgsName[i]}, RG: ${nsgsRg[i]}"
    az network nsg rule list -g ${nsgsRg[i]} --nsg-name ${nsgsName[i]} -o table
done

# ファイルに出力する場合
for((i=0; i<${#nsgsName[@]}; i++))
do
    echo "NSG name: ${nsgsName[i]}, RG: ${nsgsRg[i]}"
    az network nsg rule list -g ${nsgsRg[i]} --nsg-name ${nsgsName[i]} -o table
done > NSG-LIST.txt
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0