次の方法で共有


Azure ネットワーク用の Azure Resource Graph サンプル クエリ

このページは、Azure ネットワーク向けの Azure Resource Graph のサンプル クエリのコレクションです。

サンプル クエリ

サブスクリプションで構成されている IP アドレスを持つリソースの数

すべてのパブリック IP アドレスの一覧表示の例のクエリを使用し、summarize および count() を追加すると、構成された IP アドレスを持つリソースの一覧をサブスクリプションごとに取得できます。

Resources
| where type contains 'publicIPAddresses' and isnotempty(properties.ipAddress)
| summarize count () by subscriptionId
az graph query -q "Resources | where type contains 'publicIPAddresses' and isnotempty(properties.ipAddress) | summarize count () by subscriptionId"

ネットワーク インターフェイスの仮想ネットワークとサブネットを取得する

リソース ID プロパティから仮想ネットワークとサブネットの名前を取得するには、正規表現 parse を使用します。 parse を使用すると、複雑なフィールドからデータを取得することができますが、プロパティが存在する場合は、parse を使用せずに直接アクセスすることをお勧めします。

Resources
| where type =~ 'microsoft.network/networkinterfaces'
| project id, ipConfigurations = properties.ipConfigurations
| mvexpand ipConfigurations
| project id, subnetId = tostring(ipConfigurations.properties.subnet.id)
| parse kind=regex subnetId with '/virtualNetworks/' virtualNetwork '/subnets/' subnet
| project id, virtualNetwork, subnet
az graph query -q "Resources | where type =~ 'microsoft.network/networkinterfaces' | project id, ipConfigurations = properties.ipConfigurations | mvexpand ipConfigurations | project id, subnetId = tostring(ipConfigurations.properties.subnet.id) | parse kind=regex subnetId with '/virtualNetworks/' virtualNetwork '/subnets/' subnet | project id, virtualNetwork, subnet"

すべてのパブリック IP アドレスの一覧表示

'ストレージを含むリソースの表示' クエリと同様に、type に publicIPAddresses という語を含むものをすべて検索します。 このクエリは、そのパターンを拡張して、properties.ipAddress isnotempty の場合にのみ結果を取得し、properties.ipAddress のみを返し、結果を上位 100 件に limit します。 選択したシェルによって引用符のエスケープが必要となる場合があります。

Resources
| where type contains 'publicIPAddresses' and isnotempty(properties.ipAddress)
| project properties.ipAddress
| limit 100
az graph query -q "Resources | where type contains 'publicIPAddresses' and isnotempty(properties.ipAddress) | project properties.ipAddress | limit 100"

関連付けられていないネットワーク セキュリティ グループの表示

このクエリでは、ネットワーク インターフェイスまたはサブネットに関連付けられていないネットワーク セキュリティ グループ (NSG) が返されます。

Resources
| where type =~ 'microsoft.network/networksecuritygroups' and isnull(properties.networkInterfaces) and isnull(properties.subnets)
| project name, resourceGroup
| sort by name asc
az graph query -q "Resources | where type =~ 'microsoft.network/networksecuritygroups' and isnull(properties.networkInterfaces) and isnull(properties.subnets) | project name, resourceGroup | sort by name asc"

次のステップ