How can I create a csv with the IP address of every windows VM in vCenter?
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
Do you also have non-windows vm's in your cluster?
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!
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
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
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
Hi,
Have you tried RVTools. It will give you all your VMware infrastructure details and you can save that details in Excel / CSV.
Thanks all - much appreciated.