Skip to content

Setting computer name during OSD

Featured Replies

We are consolidating and renaming, I have a script which does not seem to work:

We want to base the OSDComputerNAme based on the current hostname, not where the computer is deployed from.

Here is the script

<><><><><>

'On Error Resume Next
Dim strComputer, newName
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
'wscript.echo strComputer & " " & objSMBIOS.SerialNumber
Select Case UCase(Left(strComputer,2))
Case "NY" newName = "HQ-" & objSMBIOS.SerialNumber
Case "NI" newName = "HQ-" & objSMBIOS.SerialNumber
Case "NM" newName = "HQ-" & objSMBIOS.SerialNumber
Case "LA" newName = "WE-" & objSMBIOS.SerialNumber
Case "AZ" newName = "WE-" & objSMBIOS.SerialNumber
End Select
wscript.echo newName
SET env = CreateObject("Microsoft.SMS.TSEnvironment")
env("OSDComputerName") = NewName
Next
<><><><><><>
Any help greatly appreciated.
Thank you.
  • Author

Peter

Thanks for looking

I placed the script right before the Apply operating system. Everything worked fine when testing, I think that the deploying tech deployed with a USB key, so the script simply did not apply, I am still trying to find out what happened.

I would prefer to do all of it with MDT (currently integrated with my SCCM 2012) however I have some complex scenario.

Hmm, this can't work. You are trying to query the AD during the PE Phase, when your Computer is not an AD member. Rather use a webservice (Maik Kosters is pretty good) to query the netbootGUID of the compuer object. This way you can retrieve the corresponding Computer Name. You can also query the SCCM database for the MAC address, which would be an Option too, to get the correct Name.

The MDT can help you there too. You can build the Computer Name directly with the customsettings.ini.

Your case select section is also missing two cases for reimaging. When your new Computer names are already set to either HQ or WE.

  • Author

Thanks for the great comments, yes, I do miss two cases...never thought about the re-imaging part.

I am not sure I understand the part of "can't work". Are you referring to the key or the bootable USB? How about if I place the script in the Refresh only section?

The goal is simple, if we refresh than have the script or MDT DB determines the name, and if bootable media than the ability to select the name, which I found what I need here

http://blogs.technet.com/b/deploymentguys/archive/2011/08/05/dynamic-computer-naming-in-zti-deployments-using-mdt-and-configmgr.aspx

 

UPDATE: the script actually works it should be in the Refresh Only. All that is left for me now is to implement the location based install.

Yes, i was referring to PXE and Media boots. You hostname will be always MININT there.

You should think about a single shot solution for the computer naming part. No reason to go with two solutions for the same task.

  • Author

I agree on a single solution, problem is MDT does not see to identify the host name in a way I can use it a in a subsection, or I simply do not know how to do it :-)

UPDATE: I solved the issue using the script above and the MDT DB + UDI screen for new computers. thanks for helping me sorting this out and giving a direction.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.