1 Reply Latest reply on May 20, 2019 10:00 AM by LucD

    Help with gettings IP's from a list.

    CHRISMY Lurker

      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.


        • 1. Re: Help with gettings IP's from a list.
          LucD Guru
          User ModeratorsvExpertCommunity Warriors

          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