PowerCLI

 View Only
  • 1.  How to get ESX ip use get-vm CLI

    Posted Jan 11, 2016 12:53 PM

    I want to use Get-vm command to get ESX ip, the sample is show below, But it cannot get the EsxIP but the ESX-name,It may has some grammar Error. Who can help me on this, Thanks

    I donot want to use get-vmhost command,because it would be very slow

    Get-VM | Select Name,id, `

    @{Name=’ESXIP’;Expression={$_.VMHost | Select ($_.ExtensionData.Config.Network.Vnic | ? {$_.Device -eq "vmk0"}).Spec.Ip.IpAddress}}



  • 2.  RE: How to get ESX ip use get-vm CLI

    Posted Jan 11, 2016 01:49 PM

    What about something like:

    get-vm | select name,vmhost

    or are you trying to find a specific vm?

    $vm = <insert vmname>

    get-vm $vm | select name,vmhost



  • 3.  RE: How to get ESX ip use get-vm CLI

    Posted Jan 11, 2016 02:07 PM

    well apparently in my lab I have my ESXhost named via IP.

    Does this help? Still runs vmhost, but only against the host with a specific vm:

    $vm = '<insert vmname>'

    $hostinfo = get-vm $vm | select vmhost

    $myhost = $hostinfo.vmhost

    get-vmhost $myhost | get-vmhostNetworkAdapter | select IP



  • 4.  RE: How to get ESX ip use get-vm CLI
    Best Answer

    Posted Jan 11, 2016 02:20 PM

    Hi, try this:

    Get-VM | Select Name, id, @{Name="IP"; Expression={$_.VMHost | Get-VMHostNetwork | Select -ExpandProperty VirtualNic |

    where {$_.PortGroupName  -match "pgManagement"} | Select IP}}

    Hope this could be useful... pay attention to -match: substitute with your correct portgroup

    Regards



  • 5.  RE: How to get ESX ip use get-vm CLI

    Posted Jan 11, 2016 03:12 PM

    Try this:

    1. Get-VM | Select Name,id, ` 
    2. @{Name="ESXIP";Expression={[system.net.dns]::gethostaddresses($_.VMHost.Name)}}


  • 6.  RE: How to get ESX ip use get-vm CLI

    Posted Jan 17, 2016 02:31 AM

    I have tryed below method,this could run:

    #consume more time

    Get-VM | Select @{N="ESXip慢";E={((Get-VMHost -VM $_).ExtensionData.Config.Network.Vnic | ? {$_.Device -eq "vmk0"}).Spec.Ip.IpAddress}}

    #a quicker method

    Get-VM | Select @{Name=’ESXIP’;Expression={ &{$script:esx=get-view -Id $_.vmhostid -property name,config};($script:esx.Config.Network.Vnic | where{$_.Device -eq 'vmk0'}).Spec.Ip.IpAddress }}