Get VM hostname on hyper-v (given VM name) using powershell

My Hyper-v has virtual machines. Hyper-v knows only virtual machine names. I want to extract the host name (which we get by running the "hostname" command on cmd in the virtual machine) on hyper-v using powershell.

+3
source share
2 answers

Do you have integration components installed on the guest? If you do not, install ASAP. After the IC is updated, you can request host information from the registry of virtual machines, for example,

gp 'HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters'
HostName                           : hyperv100.contoso.local
HostingSystemEditionId             : 8
...
PhysicalHostName                   : hyperv100
PhysicalHostNameFullyQualified     : hyperv100.contoso.local
VirtualMachineName                 : guest101

(gp 'HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters').PhysicalHostName
hyperv100

(gp 'HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters').PhysicalHostNameFullyQualified
hyperv100.contoso.local

Also, read the article that describes IC registry keys .

0
source

- IP- . , :

$VMName = "TestVMName"
$host_name = ((Get-VM | where { $_.Name -eq $VMName }) | Select -ExpandProperty NetworkAdapters).ipaddresses[0] | ForEach-Object {([system.net.dns]::GetHostByAddress($_)).hostname }

, .

0

All Articles