How to Get (Windows Server Host Name or IP) Hyper-V VM Host Name or IP Details from Debian-Based Hyper-V VM

fti-samadhan 20 Reputation points
2024-08-06T06:39:16.1133333+00:00

Hi everyone,

I'm currently running a Debian-based VM on a Windows Server 2022 Hyper-V host. I need to execute some PowerShell commands on the Windows Server from my Debian VM. Typically, I would do something like this:

ssh user@windows-server_ip 'powershell -Command "storcli.exe /c0 /vall show"'

Example : 2024_08_06_0he_Kleki(1)

However, I want to automate this process and avoid specifying the windows-server_ip or hostname every time. Is there a way to dynamically retrieve the Hyper-V host's hostname or IP from the Debian-based VM?

Hyper-V
Hyper-V
A Windows technology providing a hypervisor-based virtualization solution enabling customers to consolidate workloads onto a single server.
2,735 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,553 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. fti-samadhan 20 Reputation points
    2024-08-08T22:28:28.1266667+00:00

    I successfully retrieved the Hyper-V VM Host Name from a Debian-based Hyper-V VM.

    Since Debian 12 does not hv_kvp_daemon preinstalled, I installed it along with the hyperv package to read the necessary files:

    root@DEB-HYPV-Debian12:~# apt-get install hyperv-daemons 
    
    root@DEB-HYPV-Debian12:~# pip install hyperkv
    

    Finally, I ran hyperkv and obtained the following output:

    {
    "HostName": "WIN-SRGVS7XXXXX",
    "HostingSystemEditionId": "79",
    "HostingSystemNestedLevel": "0",
    "HostingSystemOsMajor": "10",
    "HostingSystemOsMinor": "0",
    "HostingSystemProcessorArchitecture": "9",
    "HostingSystemProcessorIdleStateMax": "0",
    "HostingSystemProcessorThrottleMax": "100",
    "HostingSystemProcessorThrottleMin": "5",
    "HostingSystemSpMajor": "0",
    "HostingSystemSpMinor": "0",
    "PhysicalHostName": "WIN-SRGVS7XXXXX",
    "PhysicalHostNameFullyQualified": "WIN-SRGVS7XXXXX",
    "VirtualMachineDynamicMemoryBalancingEnabled": "0",
    "VirtualMachineId": "18A2EE6D-B528-4103-A1BF-8B21C9FE324F",
    "VirtualMachineName": "Debian12_VM"
    }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.