获取NSG和相应的子网或NIC的列表 [英] Getting list of NSG and corresponding Subnet or NIC

查看:45
本文介绍了获取NSG和相应的子网或NIC的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谢谢.

我正在使用Azure PowerShell脚本,它将获取所有NSG,并查找它是否已连接到NIC或子网,并以CSV格式提供相同的名称.

I'm working on Azure PowerShell Script which will get all the NSG and finds whether it is attached to NIC or Subnet and give the name of the same in CSV.

我被困在解析NSG中,因为它具有SubnetsText属性,该属性以以下格式输出数据.我正在尝试使用子字符串方法来解析它,但是没有用.有人尝试过吗?

I'm stuck in parsing the NSG as it has property SubnetsText which outputs the data in below format. I'm trying to parse it using substring method but it did not work. Anybody tried this before?

[
  {
    "TapConfigurations": [],
    "HostedWorkloads": [],
    "Id": "/subscriptions/xxxx-xxxx-xxx-xxx-xxxxxx/resourceGroups/vm-test-group/providers/Microsoft.Network/networkInterfaces/testvm1VMNic"
  }
]

下面是cmdlet

$nsg = Get-AzureRmNetworkSecurityGroup -Name  testvm1NSG -ResourceGroupName vm-test-group

$nsg.SubnetsText.ToString().Substring(lastindexof('/')+1)

推荐答案

您可以执行以下操作:

$nsg.Subnets.Id.Split('/')[-1]

这将拆分/上的字符串,并从该操作中获取最后一项,即NIC名称.

this would split the string on / and get the last item from that operation, which would be the NIC name.

这篇关于获取NSG和相应的子网或NIC的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆