April 20, 2018 at 6:57 am #99303
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.
April 20, 2018 at 6:17 pm #99337
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:
April 21, 2018 at 5:53 am #99400
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.
April 20, 2018 at 6:21 pm #99339
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.
April 21, 2018 at 6:09 am #99402
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.
April 21, 2018 at 6:38 am #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.