Jump to content


  • 0
DizzleSizzle

OSD using vbs for Machine Name for Uknown Computers

Question

Hello,

 

I was looking for someone that has good VB scripting backgound that could give me a hand. Our enterprise is pretty much an all Dell shop, and our techs name the machines with the Dell service tag mainly for asset tracking. Now, I setup a Task Sequence for OSD and advertised it to the "All Unknown Computers" collection for all bare metal machines. Now I have a working script that I added into the TS that will bring up a pop-up box asking for the machine name (i know you can set this as a variable in the collection, but i like the script better), here is the script i am using for that:

 

Dim sNewComputerName, oTaskSequence, sTSMachineName

Set oTaskSequence = CreateObject ("Microsoft.SMS.TSEnvironment")

' Get the name the computer is set to receive and truncate to first 6 letters

sTSMachineName = oTAskSequence("_SMSTSMachineName")

sTSMachineName = lcase(left(sTSMachineName,6))

If sTSMachineName = "minint" Then

' The wscript.echo commands are logged in SMSTS.log for troubleshooting.

' They are not displayed to the end user.

wscript.echo "Detected that the computer name is scheduled to receive a random value. Prompting user to input a standard name."

sNewComputerName = InputBox ("Please enter a standard computer name.", "Computer Name", , 30,30)

oTaskSequence("OSDComputerName") = sNewComputerName

wscript.echo "Set Task Sequence variable OSDComputerName to: " & sNewComputerName

Else

wscript.echo "Computer set to receive a standard name, continuing as is."

End If

 

 

NOW, rather than having the script ask for a computer name and have the tech enter the asset/service Tag off the Dell, i would like to have a script like the one above, but rather than asking to enter the computer name, i would like to query the BIOS for the Dell asset tag and automatically use the results as the OSDComputerName. I have the VBS that gets the information i need from the BIOS but i can't for some reason get it to work with the TS, keeps erroring out of me. I tried to take peices from the ove script and added some lines from the below script with no luck. If anyone has a script or knows how to create one with what i have let me know. Thanks for the help/

 

DELL BIOS VBS

 

Set objWMIservice = GetObject("winmgmts:\\.\root\cimv2")

set colitems = objWMIservice.ExecQuery("Select * from Win32_BIOS",,48)

For each objitem in colitems

Wscript.echo objitem.serialnumber

Next

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

theres a few way's you could achieve this... use a vbs works well or use wsname as another option.

 

heres how we do by VBS and INI file

 



'///////////////////////////////////////////////////////////////
'//
'// Script File:
'//
'//   RenamePC.vbs
'//
'//   This script will rename this PC to the
'//   standard by pulling it's Asset tag from
'//   the BIOS or prompting the operator if that fails.
'//
'// Notes:
'//
'//   Typical modifications:
'//      None.  This program is controlled by Customer.ini
'//                          
'//////////////////////////////////////////////////////////////

' Initialization
Program = "RenamePC.vbs"
Plog "Starting"

Dim CType
Set fs = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("Wscript.Shell")
Set reg = GetObject("winmgmts:root\default:StdRegProv")

Source = ReadIni("C:\build\customer.ini", "RenamePC", "Source")
Length = trim(ReadIni("C:\build\customer.ini", "RenamePC", "Length"))
Prefix = ReadIni("C:\build\customer.ini", "RenamePC", "Prefix")

Select Case Trim(UCase(Source))
 Case "ASSET"
		Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

		Dim colSMBIOS: Set colSMBIOS = objWMIService.ExecQuery("SELECT * FROM Win32_SystemEnclosure")
		Dim objComputer, PCName

		For Each Asset in colSMBIOS
	  	tmp = trim(Asset.SMBIOSAssetTag)
		Next

		For a = 1 to Len(tmp)
	  	c = Mid(tmp,a,1)
	  	If c >= "0" And c <= "9" Then PCName = PCName + c
		next

		Do While Cint(Len(PCName)) <> Cint(Length)
	  	tmp = InputBox("Enter Asset Number.  This must be a " & Trim(length) & " digit number only.  Please ignore the text component of the Asset number if one exists.  If you can't find the PC's Asset number STOP.  You must arrange for an asset number sticker to be place on the PC before proceeding.")

	  	PCName = ""
	  	For a = 1 to Len(tmp)
	    	c = Mid(tmp,a,1)
	    	If c >= "0" And c <= "9" Then PCName = PCName + c
	  	Next

		loop

 Case "SERIAL"
		Set objWMI = GetObject("winmgmts:")
		Set colSettingsBios = objWMI.ExecQuery("Select * from Win32_BIOS")

		For Each objComputer in colSettingsBios
			PCName = Trim(objComputer.SerialNumber)
		Next			

		NotZero = False
		For a = 1 to Len(pcname)
	  	If Mid(pcname,a,1) <> "0" Then NotZero = True
		Next  	

		If Not NotZero Then PCName = ""			

		Do While cint(Len(PCName)) < cint(Length)
			PCName = InputBox("Please enter this PC's Serial Number exactly as shown on the cabinet.")
		loop
 Case "PROMPT"
		Do While cint(Len(PCName)) < Cint(Length)
			PCName = InputBox("Please enter this machines reference number and press <Enter>.")
		loop

End select

CompName = Prefix + PCName

If cint(Len(CompName)) > 15 Then CompName = Prefix + Right(pcname,15 - Len(Prefix))

PLog "Computer Name = " & CompName

Shell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName", CompName
Shell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV Hostname", CompName

PLog "Finished - Initiaing Shutdown"

SHELL.run "shutdown -r -t 5"

Function ReadIni(file, section, item)
ReadIni = ""
file = Trim(file)
item = Trim(item)
Set ini = fs.OpenTextFile( file, 1, True)

Do While ini.AtEndOfStream = False
	line = ini.ReadLine
	line = Trim(line)
	If LCase(line) = "[" & LCase(section) & "]" Then
		line = ini.ReadLine
		line = Trim(line)
		Do While Left( line, 1) <> "["
			'If InStr( 1, line, item & "=", 1) = 1 Then
			equalpos = InStr(1, line, "=", 1 )
			If equalpos > 0 Then
				leftstring = Left(line, equalpos - 1 )
				leftstring = Trim(leftstring)
				If LCase(leftstring) = LCase(item) Then
					ReadIni = Mid( line, equalpos + 1 )
					ReadIni = Trim(ReadIni)
					Exit Do
				End If
			End If

			If ini.AtEndOfStream Then Exit Do
			line = ini.ReadLine
			line = Trim(line)
		Loop
		Exit Do
	End If
Loop
ini.Close

End Function

 

 

the customer.ini component.


[RenamePC]
Length    = 6
Prefix    = TKY123
Source    = SERIAL

Share this post


Link to post
Share on other sites

  • 0

theres a few way's you could achieve this... use a vbs works well or use wsname as another option.

 

heres how we do by VBS and INI file

 



'///////////////////////////////////////////////////////////////
'//
'// Script File:
'//
'//   RenamePC.vbs
'//
'//   This script will rename this PC to the
'//   <company name> standard by pulling it's Asset tag from
'//   the BIOS or prompting the operator if that fails.
'//
'// Notes:
'//
'//   Typical modifications:
'//      None.  This program is controlled by Customer.ini
'//                          
'//////////////////////////////////////////////////////////////

' Initialization
Program = "RenamePC.vbs"
Plog "Starting"

Dim CType
Set fs = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("Wscript.Shell")
Set reg = GetObject("winmgmts:root\default:StdRegProv")

Source = ReadIni("C:\build\customer.ini", "RenamePC", "Source")
Length = trim(ReadIni("C:\build\customer.ini", "RenamePC", "Length"))
Prefix = ReadIni("C:\build\customer.ini", "RenamePC", "Prefix")

Select Case Trim(UCase(Source))
 Case "ASSET"
		Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

		Dim colSMBIOS: Set colSMBIOS = objWMIService.ExecQuery("SELECT * FROM Win32_SystemEnclosure")
		Dim objComputer, PCName

		For Each Asset in colSMBIOS
	  	tmp = trim(Asset.SMBIOSAssetTag)
		Next

		For a = 1 to Len(tmp)
	  	c = Mid(tmp,a,1)
	  	If c >= "0" And c <= "9" Then PCName = PCName + c
		next

		Do While Cint(Len(PCName)) <> Cint(Length)
	  	tmp = InputBox("Enter Asset Number.  This must be a " & Trim(length) & " digit number only.  Please ignore the text component of the Asset number if one exists.  If you can't find the PC's Asset number STOP.  You must arrange for an asset number sticker to be place on the PC before proceeding.")

	  	PCName = ""
	  	For a = 1 to Len(tmp)
	    	c = Mid(tmp,a,1)
	    	If c >= "0" And c <= "9" Then PCName = PCName + c
	  	Next

		loop

 Case "SERIAL"
		Set objWMI = GetObject("winmgmts:")
		Set colSettingsBios = objWMI.ExecQuery("Select * from Win32_BIOS")

		For Each objComputer in colSettingsBios
			PCName = Trim(objComputer.SerialNumber)
		Next			

		NotZero = False
		For a = 1 to Len(pcname)
	  	If Mid(pcname,a,1) <> "0" Then NotZero = True
		Next  	

		If Not NotZero Then PCName = ""			

		Do While cint(Len(PCName)) < cint(Length)
			PCName = InputBox("Please enter this PC's Serial Number exactly as shown on the cabinet.")
		loop
 Case "PROMPT"
		Do While cint(Len(PCName)) < Cint(Length)
			PCName = InputBox("Please enter this machines reference number and press <Enter>.")
		loop

End select

CompName = Prefix + PCName

If cint(Len(CompName)) > 15 Then CompName = Prefix + Right(pcname,15 - Len(Prefix))

PLog "Computer Name = " & CompName

Shell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName", CompName
Shell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV Hostname", CompName

PLog "Finished - Initiaing Shutdown"

SHELL.run "shutdown -r -t 5"

Function ReadIni(file, section, item)
ReadIni = ""
file = Trim(file)
item = Trim(item)
Set ini = fs.OpenTextFile( file, 1, True)

Do While ini.AtEndOfStream = False
	line = ini.ReadLine
	line = Trim(line)
	If LCase(line) = "[" & LCase(section) & "]" Then
		line = ini.ReadLine
		line = Trim(line)
		Do While Left( line, 1) <> "["
			'If InStr( 1, line, item & "=", 1) = 1 Then
			equalpos = InStr(1, line, "=", 1 )
			If equalpos > 0 Then
				leftstring = Left(line, equalpos - 1 )
				leftstring = Trim(leftstring)
				If LCase(leftstring) = LCase(item) Then
					ReadIni = Mid( line, equalpos + 1 )
					ReadIni = Trim(ReadIni)
					Exit Do
				End If
			End If

			If ini.AtEndOfStream Then Exit Do
			line = ini.ReadLine
			line = Trim(line)
		Loop
		Exit Do
	End If
Loop
ini.Close

End Function

 

 

the customer.ini component.


[RenamePC]
Length    = 6
Prefix    = TKY123
Source    = SERIAL

 

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
Answer this question...

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


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.