VMware Cloud Community
TheVMinator
Expert
Expert
Jump to solution

List Windows IPs

How can I create a csv with the IP address of every windows VM in vCenter?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can do something like this.

But be aware that this assumes you have VMware Tools installed on your VMs, in fact if you don't, you will not be able to retrieve the IP addresses in any case (at least not in this way).

Get-VM | where{$_.Guest.OSFullName -match 'windows'} |

Select Name,@{N='OS';E={$_.Guest.OSFullName}},@{N='IP';E={$_.Guest.IPAddress -join '|'}} |

Export-Csv report.csv -NoTypeInformation -UseCulture


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

View solution in original post

0 Kudos
9 Replies
vXav
Expert
Expert
Jump to solution

I wrote a function in my modules to quickly get the network info of a VM.

Import the attached script in powerCLI and run that:

Get-VMNetwork (Get-VM) | Export-CSV VM-IPs.csv

jpsider
Expert
Expert
Jump to solution

Do you also have non-windows vm's in your cluster?

0 Kudos
TheVMinator
Expert
Expert
Jump to solution

yes - I also have non-windows vms - so I want to:

get all vms

select just the windows vms

get the ip adresses

write to a csv a list of the vms and ip addresses for each vm...

Thanks!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can do something like this.

But be aware that this assumes you have VMware Tools installed on your VMs, in fact if you don't, you will not be able to retrieve the IP addresses in any case (at least not in this way).

Get-VM | where{$_.Guest.OSFullName -match 'windows'} |

Select Name,@{N='OS';E={$_.Guest.OSFullName}},@{N='IP';E={$_.Guest.IPAddress -join '|'}} |

Export-Csv report.csv -NoTypeInformation -UseCulture


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

0 Kudos
vXav
Expert
Expert
Jump to solution

Get-VMNetwork (Get-VM) | where {$_.Guest.OSFullName -like "*windows*"}| Export-CSV VM-IPs.csv 

piercj2
Enthusiast
Enthusiast
Jump to solution

Try this, I use it to get PortGroup, VLAN and IP for VM's

$outputfile = "C:\Temp\IPlist-" + (Get-Date -Format yyyy-MMM-dd-HHmm) + ".csv"

$report=@()

foreach($vm in (Get-VM)){

   $GeneralProp=[ordered]@{

        'ComputerName'=$vm.Name;

   }

   $nic = 1

   $vm | Get-VirtualPortGroup | foreach {

        $GeneralProp.Add("NIC$($nic) PortGroup",$_.Name)

        $GeneralProp.Add("NIC$($nic) VLAN ID",$_.VlanID)

        $GeneralProp.Add("NIC$($nic) IP", $vm.Guest.IPAddress[$nic-1])

        $nic++

    }

   $report += New-Object -TypeName psobject -Property $GeneralProp

  

}

# Create the .csv file

$report |

    Sort-Object -Property {($_ | Get-Member -MemberType NoteProperty).Count } -Descending |

    Export-Csv $outputfile -NoTypeInformation

Invoke-Item $outputfile

irodebush01
Contributor
Contributor
Jump to solution

This is basically what LucD‌ said, but uses the Get-View method versus Get-VM. As stated, getting the IP(s) requires VMtools to be installed and running on the vm.

$VMs = Get-View -ViewType VirtualMachine -Property Name, Guest -Filter @{"Guest.GuestId" = "Windows"}

$VMs | Select-Object Name, @{N='OS';E={$PSItem.Guest.GuestFullName}}, @{N='IP';E={$PSItem.Guest.IpAddress}} |

    Export-Csv report.csv -NoTypeInformation -UseCulture -NoClobber

UmeshAhuja
Commander
Commander
Jump to solution

Hi,

Have you tried RVTools. It will give you all your VMware infrastructure details and you can save that details in Excel / CSV.

RVTools - Home

Thanks n Regards
Umesh Ahuja

If your query resolved then please consider awarding points by correct or helpful marking.
TheVMinator
Expert
Expert
Jump to solution

Thanks all - much appreciated.

0 Kudos