Get hostname details out of Hyper-V VM

This topic contains 5 replies, has 3 voices, and was last updated by  Icey 1 month ago.

  • Author
  • #99303


    Hi All,

    Is anyone aware of a way to get a Guests computer name from a hyper-v host?

    To put context around this.... I have a script that deploys VMs using a template image (that has been sysprep) when these VMs are booted up they naturally have random names like WIN-****

    I'd like to automate the renaming of them to match the name of the VM itself in hyper-v

    I have seen ways to get the name of the hyper-v host from a guest... but id like to do the opposite.

  • #99337

    Bill Kindle

    You might be able to try using invoke-command and looking at a registry entry if you have integration services installed on the VM. I tried doing this in my lab but didn't want to waste a lot of time working out trustedhosts kinks that I ran into.

    I think this is the key you are looking for:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters

    • #99400


      Hi Bill,

      Thanks for your response. Much appreciated.

      I did have a look for that key but wasn't able to see it. I did look on a Windows 10 PC mind you in a lab environment, so I'd have to check the Server OS's at work next week.

      WDS is the way to go I'd say, but I am interested in this "Lability" ill have to check it out.

  • #99339

    Bill Kindle

    Another topic you may want to visit though is WDS. I believe you can auto generate names and auto add them to AD if that's what your ultimate goal is. There's also a nice PowerShell module called 'Lability' that would work well for setting up a lab quickly.

    Let me know if the registry key works for you.

  • #99402

    Peter Jurgens

    In my personal experience much guest info is only available through querying the guest itself (wmi or winrm). For a Server 2016 host and Server 2016 guest you could probably make use of PowerShell direct to get the hostname. I personally use Convert-WindowsImage module from the gallery and set a hostname in my unattend.xml when creating my vhdx. I've not yet automated the whole process I usually just create a vhdx, create the VM and join domain etc via console as I'm not building new servers that often.

    • #99406


      Yep I think you are correct.

      I guess you can see why there are tools that do this task already. I was just keen to automate it myself.

You must be logged in to reply to this topic.