VMware Cloud Community
samojitd
Contributor
Contributor

How to get Complete IP information (IP Address, Subnet,Gateway, DNS,WINS)

Hello Techies,

Need your help in extracting the below information in CSV file for the both Windows & Linux VM's.

1> IP Address

2> Subnet Mask

3> Gateway

4> DNS (Primary & Secondary)

5> WINS (Primary & Secondary)

I'm looking for output something like this

Server Name
Production IPProduction SubnetProduction GatewayProduction DNS1Production DNS2Production WINS1Production WINS2Backup IPBackup SubnetBackup GatewayBackup DNS1Backup DNS2

Backup

WINS1

Backup WINS2

Win2K12
RHEL6
RHEL7

Thanks in advance,

Samojit Das

Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership

If these VMs have VMware Tools installed, that information can be retrieved.

But you will have to provide some more information.

  • What kind of guest OSes are running on these VMs?
    • This info is required to know which command to run to retrieve the IP info
  • What exactly is meant by the Production and Backup entries? Does this mean these VMs each have 2 vNICs mapped to different subnets?


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

Reply
0 Kudos
samojitd
Contributor
Contributor

Hello LucD,

Sorry for the confusion.

Yes VM tools are Running and Current.

The OS which are configured are from Win2K to Win2K12 and RHEL 4 to 7.

Yes 2 NIC's mapped to different subnets along with different IP,Subnet,gateway,DNS & WINS servers.

Let me know if you have any other concerns.

Thanks,

Samojit Das

Reply
0 Kudos
LucD
Leadership
Leadership

Just one, how do you determine which NIC is Production and which is Backup?


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

Reply
0 Kudos
samojitd
Contributor
Contributor

Do you mean at the OS level then its like Front LAN (Prod) & backup lan (backup) in windows.

and if Linux/ Unix then with eth0(Prod) & eth1 (backup).

From vCenter level we can determine using the IP range like for Prod it will be X.X.X.X & backup will be y.y.y.y

Reply
0 Kudos
samojitd
Contributor
Contributor

Currently this is how am trying to extract the details

Currently this what I'm trying

Import-csv E:\Samojit_Data_backup_27Dec2017\D\Scripts\Server_List.csv |

foreach {

$server = $_.ServerName

foreach ($servers in $server) {

Get-VM -Name $servers | Select Name,

@{N="IP Address";E={[string]::Join(", ", @( $_.guest.IPAddress | where {($_.Split(".")).length -eq 4}))}},

@{Name="Primary DNS";E={$_.ExtensionData.Guest.net.dnsconfig.IpAddress[0]}},

@{Name="Secondary DNS";E={$_.ExtensionData.Guest.net.Exportdnsconfig.IpAddress[1]}},

@{Name="Primary WINS";E={$_.ExtensionData.Guest.net.netbiosconfig.primarywins}},

@{Name="Secondary WINS";E={$_.ExtensionData.Guest.net.netbiosconfig.SecondaryWINS}},

@{N='Gateway';E={[string]::Join(',',($vm.ExtensionData.Guest.IpStack.IpRouteConfig.IpRoute | %{if($_.Gateway.IpAddress){$_.Gateway.IpAddress}}))}} |

Export-CSV -path E:\Samojit_Data_backup_27Dec2017\D\Scripts\VM_List_Target.csv -NoTypeInformation -UseCulture  -Append }

Reply
0 Kudos
LucD
Leadership
Leadership

And what is the problem with that code?


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

Reply
0 Kudos
samojitd
Contributor
Contributor

Not getting the desired output.

        

NameIP AddressPrimary DNSSecondary DNSPrimary WINSSecondary WINSGatewaySubnet Mask
RHEL7_SAMOJIT192.168.10.66
RHEL6_Samojit192.168.10.61
WIN2K8_Samojit192.168.10.247, 192.168.10.242192.168.10.50192.168.10.255192.168.10.254
Reply
0 Kudos