/build/static/layout/Breadcrumb_cap_w.png

Get hostname through script

Hi,

We've got a sysprepped XP imported in kace.
With altiris we got in the sysprep.inf file "Computername=%name%" where altiris changed the %name% to the name given in the deployment solution.
Now we would like to do the same with kace.
Is there any documentation on how to retrieve the hostname from the system inventory right after the deployment of the system image but before the unattended setup to modify the sysprep.inf on the target system ?

Thx in advance

Grts,
Tom

0 Comments   [ + ] Show comments

Answers (5)

Posted by: cserrins 12 years ago
Red Belt
1
Tom,

There are several options, depending on if this is a brand new machine, or a machine that is being reimaged. You can take a look at the collect/apply computer name tasks. You put the collect as the first preinstall task and it will get the name, you put the apply as a mid-level task and it will apply it to your sys prep.inf file.

With a brand new machine, you should use get/set computer name (which can be used for the above step as well). This is a script that a collegue and I wrote that will let you have "get" prompt you with a dialog box to enter the name you wish to give this brand new box.

Lastly, you also have the abilitiy to use wsname.exe. There is a built in naming rule as a post install task, or you can create your own by including wsname as a post install (PO) task.

Corey
Posted by: toj 12 years ago
Senior Yellow Belt
1
If other people are interested in the solution we're using :

With the KBE-manipulator 3.4 you can regenerate a KBE with the mySQL-drivers installed. So you can finally make/deploy WIM-images and connect to the mysql database from the K2000. After deploying the sysprepped XP image to the system an post-installation task, in the KBE-windows-environment (vbs, see below), will execute. The script will retrieve the hostname from the K2000 database (based on the mac-address) with a read-only account, and change the variable %NAME% in the sysprep.inf

The mini-setup from Windows XP will launch and use the given hostname in the K2000.



'*****************************************************************************************
'*
'* Script name : KACE_XP_ChangeHostname.vbs
'* Owner : TOJ
'* Last Change : 14/03/2012
'* Purpose : Change hostname XP + Copy sysprep to local machine
'*
'*****************************************************************************************

Const ForReading = 1
Const ForWriting = 2
Dim objShell, objFSO, objFile, objWMIService, colItems, objItem, objProperties, objEnv
Dim strHostName, strMAC, strSysprepRemote, strSysprepLocal, strTemp, strText, strSQL, strModel

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")

'sysprep.txt contains as a computername %NAME%
strSysprepRemote = "\\K2000_HOSTNAME\petemp\imagestore\sysprep.txt"
strSysprepLocal = "C:\sysprep\sysprep.inf"




'*****************************************************************************************
'* Get only the first MAC address from computer
'*****************************************************************************************
strMAC = ""
strSQL = "SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID > '"

Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems = objWMIService.ExecQuery( strSQL, "WQL", 48 )

For Each objItem In colItems
strMAC = objItem.MACAddress
Exit For
Next
If strMAC = "" Then strMac = "ERROR"


'*****************************************************************************************
'* Retrieve hostname from K2000
'*****************************************************************************************
Dim objCN, strCNString, objRS

strSQL = "SELECT * FROM IM_NODE where mac = '" & strmac & "'"
strCNString = "DRIVER={MySQL ODBC 5.1 Driver}; SERVER=KACE_HOSTNAME; DATABASE=KBDB; UID=K2000_USERID;PASSWORD=K2000_PASSWORD; OPTION=3"

'create an instance of the ADO connection and recordset objects
Set objCN = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.Recordset")

'Open the connection to the database
objCN.Open strCNString
objRS.Open strSQL,objCN

'first of all determine whether there are any records
Do While NOT objRS.Eof
If len(replace(objRS("HOST_NAME"), " ", "")) > 0 Then strHostName = objRS("HOST_NAME")
objRS.MoveNext
Loop
If strHostName = "" Then strHostName = "ERROR"

objRS.Close
Set objRS=nothing
objCN.Close
Set objCN=nothing




'*****************************************************************************************
'* Replace local sysprep file
'*****************************************************************************************
Set objFile = objFSO.OpenTextFile(strSysprepRemote, ForReading)
strTemp = objFile.ReadAll
objFile.Close
strText = Replace(strTemp, "ComputerName=%NAME%","ComputerName=" & strHostName )
Set objFile = objFSO.CreateTextFile(strSysprepLocal, true)
objFile.WriteLine strText
objFile.Close


wScript.quit
Posted by: toj 12 years ago
Senior Yellow Belt
0
Corey,

Thx for the quick respons, but our main purpose is to deploy new computers...
Now we got a numbering of computers once started with 1 --> PC1845

If we want to deploy computers the main condition is that it can be done without interaction of users nor manual interventions.
That script of yours is popping up and stays there until someone makes a manual intervention.

With the wsname you still have to manually enter or adjust (by parameter) the computername when you want to deploy a system.

We've got computers in the system inventory, when you click on a system there is a field "Host Name" that you can use to give the system a more meaningful name the the ipaddress. The value of that hostname we would like to use to name the computer. With a pre-installation task we would like to retrieve the value of "host name" of the computer we're deploying and then by scripting we can change the sysprep.inf.

Our problem is that we don't know how or where we can retrieve the value of "host name" of the computer we want to deploy.

Grts,
Tom
Posted by: cserrins 12 years ago
Red Belt
0
So will you be manually entering in the Host Name under each system? that seems more tedious than wsname.

If you are trying to get the hostname from the K2000, I could probably assist with that, Let me know,

Corey
Posted by: toj 12 years ago
Senior Yellow Belt
0
If you are trying to get the hostname from the K2000, I could probably assist with that, Let me know,

Thats indeed what we would like to do...


Grts,
Tom
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ