Forum Discussion
Hyper-V Default switch IP address range change. Ver 1809 Build 17763.1
But in general, why is that so hard to achieve compared to other solutions?
It's far easier in Linux world
Well i don't know how it can be easier in Linux where most of the things must be done from Terminal and manually typing codes
- LisendraMay 11, 2020Copper Contributor
southernprogrammer Thanks, gived myself permission to tweak a litlle you script to update all my vmdomains's ip also, work like a charm.
I also think the behavior of the default adapter is not logical, and i personaly see it as a bug, i hope it get fixed since i am migrating from VmWare to Hypre-V, streamlining my setup accross multiple device is better without scripts...
- HotCakeXFeb 27, 2020MVPThank you! i'll save it in my notes
- southernprogrammerFeb 27, 2020Copper Contributor
HotCakeX I'm talking about accessing a url that is hosted inside the guest.
If doing development you could do remote debugging on your host while having your environment on your guest.
- HotCakeXFeb 27, 2020MVP
Thanks, but Hyper-V VMs with enhanced session allow drag and drop between guest and host.
or is the script for a specific situation only?
- southernprogrammerFeb 27, 2020Copper Contributor
If you just need to access resources on your guest from the host, you could just have a powershell script that you can run on the host after launching the VM.
Replace 'BryanDev' with the name of your VM and replace "weirdalvm.3-gis.com" with your desired url you want to access the resource with.
Run as administrator
$result = get-vm -Name BryanDev | Select -ExpandProperty Networkadapters | Select IPAddresses | ft -hidetableheaders | Out-String $result = $result.Split(",")[0].Trim().Replace("{", "").Replace("}", "") function setHostEntries([hashtable] $entries) { $hostsFile = "$env:windir\System32\drivers\etc\hosts" $newLines = @() $c = Get-Content -Path $hostsFile foreach ($line in $c) { $bits = [regex]::Split($line, "\s+") if ($bits.count -eq 2) { $match = $NULL ForEach($entry in $entries.GetEnumerator()) { if($bits[1] -eq $entry.Key) { $newLines += ($entry.Value + ' ' + $entry.Key) Write-Host Replacing HOSTS entry for $entry.Key $match = $entry.Key break } } if($match -eq $NULL) { $newLines += $line } else { $entries.Remove($match) } } else { $newLines += $line } } foreach($entry in $entries.GetEnumerator()) { Write-Host Adding HOSTS entry for $entry.Key $newLines += $entry.Value + ' ' + $entry.Key } Write-Host Saving $hostsFile Clear-Content $hostsFile foreach ($line in $newLines) { $line | Out-File -encoding ASCII -append $hostsFile } } $entries = @{ 'weirdalvm.3-gis.com' = $result }; setHostEntries($entries)