Automation

 View Only
  • 1.  Grabbing VM ipaddress via PowerCLI

    Posted Jan 16, 2015 06:23 AM

    Hi All,

    I'm familiar with running the following in order to see the IPaddresses for a given VM:

    # Grab all VMs through this view

    $a = get-view -viewtype virtualmachine

    # Suppose the 1st VM has multiple IP addresses

    $a[0].guest.ipaddress

    That would return me the array of IPaddresses for the given VM.

    The issue I'm experiencing currently is when I do this very same thing, the data pulled back is a SINGLE IPaddress for every VM. I can't figure out what has changed. I have confirmed using the Get-VM cmdlet will pull the IPaddress info as I'm accustomed to. I originally chose the VIEW route since I'm dealing with large numbers of VMs and the view was much quicker than the Get-VM cmdlet. If anyone has suggestions or questions please let me know. Thanks for reading!

    -Josiah

    I'll be hovering in the Freenode IRC #powercli channel for the next day or so 'till this is put to bed to some degree of closure ^.^

    PS - Something I have noticed is the $_.guest.net.ipaddress property is not preserved (not sure if that's the right word choice) when taking the get-view and exporting it via CLIXml (export-clixml); in the .xml export this $_.guest.net.ipaddress does not exist from what I see. My original thought was to simply grab all VM-view data from another environment, then export via CliXML, take back to home base & chop it up from there. Looks like I'll need to handle a little more over on the other environment-end before bringing back to home base. Cheers.



  • 2.  RE: Grabbing VM ipaddress via PowerCLI

    Posted Jan 16, 2015 06:41 AM

    Does this return what you expect ?

    Get-View -ViewType VirtualMachine |

    Select Name,@{N='IP';E={[string]::Join(',',$_.Guest.IPAddress)}}



  • 3.  RE: Grabbing VM ipaddress via PowerCLI

    Posted Jan 16, 2015 08:14 AM

    Thanks for the reply and suggestion. The piece you provided results in the same. None of the VMs which have more than 1 IP are showing that here.

    NameIp
    Host-01SingleIp
    Host-02SingleIp
    Host-03SingleIp
    Host-04SingleIp


  • 4.  RE: Grabbing VM ipaddress via PowerCLI

    Posted Jan 16, 2015 08:23 AM

    Do you see the 2nd IP address in the vSphere client (when you select the VM and look under Summary - General) ?



  • 5.  RE: Grabbing VM ipaddress via PowerCLI

    Posted Jan 16, 2015 08:35 AM

    Yes, there are a total of 4 IP's for a few VM's and I see them each in the Summary tab's General section (via the View all option). While I'm able to continue w/my efforts through use of the Get-VM cmdlet, I'm stumped on what's up w/the view. I tried the same efforts in another environment (different ViServer), and a single IP is returned there as well via the view. I don't know what to think >.<



  • 6.  RE: Grabbing VM ipaddress via PowerCLI
    Best Answer

    Posted Jan 16, 2015 08:36 AM

    Try this :

    Get-View -ViewType VirtualMachine |Select @{N='IP';E={[string]::Join(',',$_.Guest.net.IPAddress)}}

    Also on my side, I only see one IP address in guest.IPAddress, but in guest.net.IPAddress they are all listed



  • 7.  RE: Grabbing VM ipaddress via PowerCLI

    Posted Jan 16, 2015 08:51 AM

    That does it! I imagine I missed something which likely alluded to $_.guest.IpAddress no longer working in some way or another along w/the suggestion to use guest.net.IpAddress in its place. I thank you both for your attention and time/assistance.

    Regards,

    Josiah