我想生成包含VM名称和附加到它们的网络接口的CSV文件。当我运行cmdlet时,我看到表格式的以下输出
ResourceGroupName Name Location VmSize OsType NIC
当我尝试使用命令Get-AzureRmVM | select-object NIC
仅选择NIC对象时,输出为空白。
有人可以指导我如何过滤掉NIC名称和VM名称吗?
答案 0 :(得分:0)
由于NIC不是Get-AzureRmVm
中的项目,因此我们无法使用Get-AzureRmVM | select-object NIC
获取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;}
任何人都可以指导我如何过滤出NIC名称和VM 名字?
作为解决方法,我们可以使用此脚本获取NIC名称:
$a = get-azurermvm -ResourceGroupName jasonvm -Name jasonvm
$b = $a.NetworkProfile.NetworkInterfaces.id -split "/"
$nic = $b[-1]
$nic
然后我们可以使用$nic
来获取有关NIC的信息,如下所示:
Get-AzureRmNetworkInterface -Name $nic -ResourceGroupName jasonvm