如何使用 Get-AzureRmVM cmdlet 提取 NIC 信息

How to extract NIC information using Get-AzureRmVM cmdlet

我想生成包含 VM 名称和附加到它们的网络接口的 CSV 文件。当我 运行 cmdlet 时,我看到以下 table 格式的输出

ResourceGroupName Name Location VmSize  OsType NIC

当我尝试使用命令 Get-AzureRmVM | select-object NIC 仅 select NIC 对象时,输出为空白。

谁能指导我如何过滤掉 NIC 名称和 VM 名称?

因为网卡不是Get-AzureRmVm中的项目,所以我们无法使用Get-AzureRmVM | select-object NIC获取网卡名称:

PS D:\testdata> get-azurermvm | gm


   TypeName: Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineList

Name                     MemberType Definition
----                     ---------- ----------
Equals                   Method     bool Equals(System.Object obj)
GetHashCode              Method     int GetHashCode()
GetType                  Method     type GetType()
ToPSVirtualMachine       Method     Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine ToPSVirtualMachine()
ToString                 Method     string ToString()
AvailabilitySetReference Property   Microsoft.Azure.Management.Compute.Models.SubResource AvailabilitySetReference {...
DiagnosticsProfile       Property   Microsoft.Azure.Management.Compute.Models.DiagnosticsProfile DiagnosticsProfile ...
DisplayHint              Property   Microsoft.Azure.Commands.Compute.Models.DisplayHintType DisplayHint {get;set;}
Extensions               Property   System.Collections.Generic.IList[Microsoft.Azure.Management.Compute.Models.Virtu...
HardwareProfile          Property   Microsoft.Azure.Management.Compute.Models.HardwareProfile HardwareProfile {get;s...
Id                       Property   string Id {get;set;}
Identity                 Property   Microsoft.Azure.Management.Compute.Models.VirtualMachineIdentity Identity {get;s...
InstanceView             Property   Microsoft.Azure.Management.Compute.Models.VirtualMachineInstanceView InstanceVie...
LicenseType              Property   string LicenseType {get;set;}
Location                 Property   string Location {get;set;}
Name                     Property   string Name {get;set;}
NetworkProfile           Property   Microsoft.Azure.Management.Compute.Models.NetworkProfile NetworkProfile {get;set;}
OSProfile                Property   Microsoft.Azure.Management.Compute.Models.OSProfile OSProfile {get;set;}
Plan                     Property   Microsoft.Azure.Management.Compute.Models.Plan Plan {get;set;}
ProvisioningState        Property   string ProvisioningState {get;set;}
RequestId                Property   string RequestId {get;set;}
ResourceGroupName        Property   string ResourceGroupName {get;}
StatusCode               Property   System.Net.HttpStatusCode StatusCode {get;set;}
StorageProfile           Property   Microsoft.Azure.Management.Compute.Models.StorageProfile StorageProfile {get;set;}
Tags                     Property   System.Collections.Generic.IDictionary[string,string] Tags {get;set;}
Type                     Property   string Type {get;set;}
VmId                     Property   string VmId {get;set;}

Can anyone guide me on how to filter out the NIC names and the VM names ?

作为解决方法,我们可以使用此脚本获取 NIC 名称:

$a = get-azurermvm -ResourceGroupName jasonvm -Name jasonvm
$b = $a.NetworkProfile.NetworkInterfaces.id -split "/"
$nic = $b[-1]
$nic

然后我们可以使用$nic获取网卡的信息,像这样:

Get-AzureRmNetworkInterface -Name $nic -ResourceGroupName jasonvm