PowerCLI

 View Only
  • 1.  How can Get-VM return the guest FQDN and IP Address ?

    Posted Sep 01, 2017 07:22 PM

    Newbie here to VMWare. I need to extract all guest VMware info to build a database for a Remote Desktop Client (RDP) and VMWare console solution.

    I love how Connect-VIServer will connect me to all my clusters!

    I'm currently using this command:

    $temp = Get-Cluster -Server $global:DefaultVIServers -PipelineVariable cluster | Get-VM | select-object Name,Folder,Guest,PowerState,VMHost,PersistentId,Uid

    What is the best way to add the guest FQDN and IP address?

    I did also see get-view.  Is get-view a legacy command?

    Thanks, Stu



  • 2.  RE: How can Get-VM return the guest FQDN and IP Address ?

    Posted Sep 02, 2017 07:20 PM

    Hi Stu,

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

    Perhaps this may help for the FQDN? Retrieve Domain Name for Guest VMs using PowerCLI – Deans Blog

    Good luck!



  • 3.  RE: How can Get-VM return the guest FQDN and IP Address ?

    Posted Sep 03, 2017 07:50 AM

    Try something like this, but note that the Guest properties are only containing values when the VMware Tools are installed, and when the VM is powered on.

    Get-Cluster -Server $global:DefaultVIServers -PipelineVariable cluster |

    Get-VM |

    select-object Name,Folder,Guest,PowerState,VMHost,PersistentId,Uid,

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

        @{N='FQDN';E={$_.ExtensionData.Guest.IPStack[0].DnsConfig.HostName,

            $_.ExtensionData.Guest.IPStack[0].DnsConfig.DomainName -join '.'}}

    The Get-View is a regular PowerCLI cmdlet, and it gives you access to the vSphere objects.

    In short there are two types of objects when working with PowerCLI:

    • the .Net objects are the ones that are returned by the PowerCLI cmdlets. For example the VirtualMachine object returned by Get-VM. These objects contain a selection, made by the PowerCLI Dev Team, of the corresponding vSphere object.
    • the vSphere objects. These are documented in the API Reference, and are the actual objects that vSphere uses internally. An  example is the VirtualMachine object. Notice how this vSphere object has much more properties than the corresponding .Net object.

    With Get-View you can access the vSphere object from a .Net object.

    For example:

    Get-VM -Name MyVM | Get-View

    You can also access the vSphere object through the ExtensionData property of the .Net object (which I used in the FQDN calculated property above.