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}}
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
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
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
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
Try this:
@{Name=
"ESXIP"
;Expression={[system.net.dns]::gethostaddresses($_.VMHost.Name)}}
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 }}