VMware Cloud Community
CHRISMY
Contributor
Contributor

Help with gettings IP's from a list.

Hi Everyone,

I've been trying to piece together a powercli script that will pull the IP address from each VM in a text file list. I can get as far as polling ALL VM's and displaying to the terminal with this:  Get-VM | Select Name, @{N="IP Address";E={@($_.guest.IPAddress[0])}}

The problem though is that I only need a particular set of VM's, not all, and I need to export it to a .csv file. I've been working on it so long with so many variations that now I've just confused myself. Can someone help with the correct syntax?  I know I have to use the Export-CSV commandlet but I've had it ask for the object and retun and empty file.

Thanks.

0 Kudos
1 Reply
LucD
Leadership
Leadership

Try something like this.

The names of the VMs can be specified in the .txt file, one name per line.

Get-Content -Path .\vmnames.txt |

ForEach-Object -Process {

   Get-VM -Name $_ | Select Name, @{N = "IP Address"; E = { @($_.guest.IPAddress[0]) } }

} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


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

0 Kudos