1

Background:

I am attempting to set the host name using a registry key, as I'm deploying a virtual machine and would like to have the host name set based on the guest VM's name. This is the script I'm using to set the host name:

$OSDComputerName = (New-Object -comobject WScript.shell).RegRead("HKLM\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters\VirtualMachineName")
$tsenv = New-Object -ComObject Microsoft.SMS.TSEnvironment
$tsenv.Value("OSDComputerName") ="$OSDComputerName"

The task sequence location:

enter image description here

Problem:

Unfortunately, it fails to set the host name, using instead an autogenerated host name.

Question:

At what point does the registry become established during the task sequence?

Davidw
  • 1,210
  • 3
  • 14
  • 24
  • Do you have any error logged in your task sequence logs when you try to set the hostname? If so, what is it (or what are they)? – Aura May 02 '19 at 22:39
  • Is that going to be on the client or the server? (I sometimes have trouble finding config manager logs.) – Davidw May 02 '19 at 23:02
  • If you boot your VM to the SCCM boot media and press F8 you should get a command-line window. You can then run regedit and look to see if the registry key you're querying actually exists in the Windows PE environment, my guess would be that it does not. There will always be a registry, that's a fundamental part of Windows, but individual keys might or might not exist at various stages in the install process. – Harry Johnston May 03 '19 at 06:50
  • As Harry already said the main problem is probably that your are in WinPE here not in full Windows. PE has a very reduced set it exists only in a ram disk and I doubt you have the whole VM info at that point. You are in full windows after the step "Setup Windows and ConfigMgr" (actually it happens with a reboot that step does so half the step is pe other half not) it might be too late to set osdcomputername there though so you could have to resort to some network query to figure out your host as I am not sure WinPE has any info about it (I don't know for certain though so maybe it has) – Syberdoor May 03 '19 at 09:19
  • If the computers aren't in a domain, it should be straightforward enough to change the computer name later on in the SCCM sequence. Don't see any easy way to handle the case where you're using SCCM to join the computer to a domain. There might be some other way to extract the VM name, you'd need to check with a HyperV expert. (It might be as easy as installing the right device driver in the boot image or something.) – Harry Johnston May 05 '19 at 21:30
  • These are in a domain. – Davidw May 05 '19 at 23:10
  • However, now that you mention that, I wonder if putting the computer name step prior to the domain join would make a difference? – Davidw May 06 '19 at 00:43

0 Answers0