HyperV2Hosts is a PowerShell script that fetches IP addresses of active Hyper-V VMs and updates your hosts file with VM names and their IPs.
The script adds entries in the hosts file using the format IP VMName # [HYPERV2HOSTS]
.
- Windows operating system with PowerShell
- Administrator privileges
-
Clone or download this repository.
-
Open PowerShell with administrative privileges.
-
Navigate to the cloned/downloaded directory:
cd path/to/HyperV2Hosts
- Run the script:
.\hyperV2hosts.ps1
- Check your hosts file at
%SystemRoot%\System32\drivers\etc\hosts
to see the updated entries.
- If you get some error about_Execution_Policies just use this command:
powershell.exe -noprofile -executionpolicy bypass -file .\hyperv2hosts.ps1
- If IP does not show up, one might have to install linux-azure on the guest (https://learn.microsoft.com/en-us/windows-server/virtualization/hyper-v/supported-ubuntu-virtual-machines-on-hyper-v).
- You can also add this script to task scheduler.
Inspired by hyperv2hosts
Written almost completely using ChatGPT. This README.md too :)