VMware Cloud Community
Igor5
Contributor
Contributor

How to add the correct values DNS,Gateway,Mask

Hi!
Help me figure out the problem!
I can't find the correct values for DNS, Gateway, Mask. So that each address corresponds to the correct value DNS, Gateway, Mask.

Script:

Get-Cluster | Get-VM -PipelineVariable vm | Get-NetworkAdapter |
Select @{N='VM';E={$vm.Name}},NetworkName, MacAddress,
@{N=”IP Address”;E={
$nic = $_
$ips = ($vm.Guest.Nics | where{$_.Device.Name -eq $nic.Name}).IPAddress
($ips | where{([ipaddress]$_).AddressFamily -eq 'InterNetwork'}) -join '|'}},
@{N='Gateway';E={($VM.ExtensionData.Guest.IpStack.IpRouteConfig.IpRoute.Gateway.IPaddress | where{$_ -ne $null}) }},
@{N="DNS";E={$vm.ExtensionData.Guest.IpStack.DnsConfig.IpAddress}},
@{N="Subnet Mask";E={$vm.ExtensionData.Guest.Net.IpConfig.IpAddress.PrefixLength}},
@{N='OS';E={$vm.Guest.OSFullName}},
@{N="Attributes";E={[string]::Join('|',($VM.ExtensionData.Value.Value))}} | Out-GridView

0 Kudos
4 Replies
LucD
Leadership
Leadership

What is the problem?
This seems to work for me.
Do you have the VMware Tools installed on those VMs?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Igor5
Contributor
Contributor

The script works and brings information.
But if I have 4 network interfaces, then the gateway, DNS and mask are going into one. And I want each interface to correspond to its gateway, DNS and mask.

0 Kudos
LucD
Leadership
Leadership

As far as I can see there is no way to split out the DNS information by vNIC.

The only solution I see to ask inside the Guest OS, by for example Invoke-VMScript


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Tags (1)
Igor5
Contributor
Contributor

Thanks for the help. I tried to make a match by values, but nothing came out. That's why I wrote here. I thought they would help me here.

0 Kudos