Set the computer description during the build process

By | January 6, 2014

I recently had a request from a client to add a description to the computer account entry in AD during the build process. The client required both the serial number of the machine and the model of the machine to be recorded in the description field of the AD computer account properties. I had seen a number of different ways of doing this in the past but wanted something that was quick an easy to implement that didn’t require a webservice or a editing the MDT xml files.

My solution was the below script which was executed via a run command line step in the task sequence. The only requirement for this is that the account used to run the script has the necessary permissions to update AD objects.

 

 

'# *************************************************************************
'#
'# Script Name: set-ComputerDescription.vbs
'# Version:     1.0
'# Author:      Steve Rollins
'# Date:        12th December 2013
'#
'# Description: Adds the Serial Number and PC model to the description field 
'#				of the computer account object in AD
'#
'#
'# *************************************************************************

strModel = GetModelInfo
strSerial = GetSerialNumber  

strDescription = "SN:" & strSerial  & " Model:" & strModel

UpdateAD

Function GetSerialNumber   
        strComputer = "."   
        Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")   
		Set colBIOS = objWMIService.ExecQuery("Select * from Win32_BIOS")   
        For each objBIOS In colBIOS   
            GetSerialNumber = objBIOS.SerialNumber   
        Next   
End Function 

Function GetModelInfo   
        strComputer = "."   
		Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
		Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
		For Each objItem in colItems
          GetModelInfo = objItem.Model
		next

End Function 

Sub UpdateAD  
        Set objSysInfo = CreateObject("ADSystemInfo")
On Error Resume Next            
        Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)   
        objComputer.Description = strDescription   
        objComputer.SetInfo  
End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *