如何从基于 Debian 的 Hyper-V VM 获取(Windows Server 主机名或 IP)Hyper-V VM 主机名或 IP 详细信息

问题描述 投票:0回答:1

我目前正在 Windows Server 2022 Hyper-V 主机上运行基于 Debian 的虚拟机。我需要从我的 Debian VM 在 Windows Server 上执行一些 PowerShell 命令

SSH 与 PowerShell 远程处理

我正在使用 SSH 登录 Windows Server 并运行 PowerShell 命令:

但我想避免每次手动提供 Windows Server IP,并简化从基于 Debian 的虚拟机运行 PowerShell 命令的过程。

通常,我会做这样的事情:

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

示例: enter image description here

但是,我想自动化此过程并避免每次都指定 windows-server_ip 或主机名。有没有办法从基于 Debian 的虚拟机动态检索 Hyper-V 主机的主机名或 IP?

windows powershell ssh debian hyper-v
1个回答
0
投票

我成功从基于 Debian 的 Hyper-V VM 检索了 Hyper-V VM 主机名。

由于 Debian 12 没有预安装 hv_kvp_daemon,所以我将其与 hyperv 软件包一起安装以读取必要的文件:

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

最后,我运行 hyperkv 并获得以下输出:

{

"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"

}
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.