Jump to content


Sign in to follow this  
kaisersose1995

Surface Pro 3 OSDComputerName from AssetTag

Recommended Posts

Just thought I'd share a script I wrote this morning. I currently have a task sequence that builds various devices and takes the OSDComputerName variable from the Asset Tag BIOS field. The Surface Pro 3 works a little different, in that you can't set this field directly from the BIOS, you need to set it using a CLI utility (available here - http://www.microsoft.com/en-us/download/details.aspx?id=44076).This usually means booting a brand new device, going through the OOBE stuff, running the CLI utility, then restarting into PXE and continuing with imaging as normal. The below .vbs script first checks if there is an existing asset tag entered, and if not prompts the user to enter a machine name, which it then uses in the Task Sequence and sets the tag locally using the utility, so the next time the device is built it just takes the tag straight from the BIOS.

 

Dim objWMIService
Dim colItems
Dim objSMSEnv
Dim strNewName
Dim WshShell
Dim strCurDir

Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_SystemEnclosure")
 
'Get the current Asset Tag
For Each objItem In colItems
  'Remove all beginning, trailing and containing spaces and switch to uppercase
  strNewName = objItem.SMBIOSAssetTag
Next

wscript.echo "Currently using " & strNewName & " as OSDComputerName"

If left(strNewName,4) <> "SomeString" Then 
	Do While X = 0
		strNewName = InputBox ("Please enter a machine name i.e. HP-XXXXXX","Enter Machine Name...")
		If strNewName = "" Then
			Wscript.Echo "You must enter a machine name."
		Else
			Set WshShell = WScript.CreateObject("WScript.Shell")
			strCurDir = WshShell.CurrentDirectory			
			WshShell.Run strCurDir & "\AssetTag -s " & UCase(strNewName), 0
			
			wscript.echo "Currently using " & strNewName & " as OSDComputerName
			
			Set objSMSEnv = CreateObject("Microsoft.SMS.TSEnvironment")
			wscript.echo "Set Task Sequence variable OSDComputerName to: " & strNewName
			objSMSEnv("OSDComputerName") = UCase(strNewName)
			Exit Do
		End If
	Loop
Else
	Wscript.Echo strNewName
	Set objSMSEnv = CreateObject("Microsoft.SMS.TSEnvironment")
	wscript.echo "Set Task Sequence variable OSDComputerName to: " & strNewName
	objSMSEnv("OSDComputerName") = UCase(strNewName)
End If 

Set WshShell = Nothing

I deployed it by having AssetTag.exe and script file in a folder on my SCCM OSD scripts directory, then created a simple package without program and pointed at this location. After distributing to my local DPs I then created a Run Command Line task sequence item and added the name of the script file into the Command Line area, making sure to reference the package containing the script.

 

post-30938-0-88803500-1440071185_thumb.jpg

Share this post


Link to post
Share on other sites


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...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...