Wednesday, May 25, 2011

Setting Computer Description using the field in MDT Wizard

The MDT Wizard .hta has a hidden field for setting the ComputerDescription.  Using the WizardEditor this field can be made visable in the Wizard and then you can add code to your deployment to consume the data entered in the field.

Here is a simple script based on ZTITemplate.wsf for consuming the ComputerDescription task Sequence variable. Save the script in your %SCRIPTROOT% folder along with the other ZTI Scripts as ZTIDESCRIPTION.wsf.  Add a Task Sequence Step to call the script somewhere in your Task Sequence.

<job id="ZTIDescription">
<script language="VBScript" src="ZTIUtility.vbs"/>
<script language="VBScript">

' //***************************************************************************
' // ***** Script Header *****
' //
' // Solution: Solution Accelerator for Microsoft Deployment
' // File: ZTIDescription.wsf
' //
' // Purpose: Set Computer Description in AD based on the MDT Wizard Computer Description Field
' //
' // Usage: cscript ZTIDescription.wsf [/debug:true]
' //
' // Customer Build Version: 1.0.0
' // Customer Script Version: 1.0.0
' // Customer History:
' //
' // ***** End Header *****
' //***************************************************************************

'//----------------------------------------------------------------------------
'//
'// Global constant and variable declarations
'//
'//----------------------------------------------------------------------------

Option Explicit

Dim iRetVal

'//----------------------------------------------------------------------------
'// End declarations
'//----------------------------------------------------------------------------

'//----------------------------------------------------------------------------
'// Main routine
'//----------------------------------------------------------------------------

On Error Resume Next
iRetVal = ZTIProcess
ProcessResults iRetVal
On Error Goto 0

'//---------------------------------------------------------------------------
'//
'// Function: ZTIProcess()
'//
'// Input: None
'//
'// Return: Success - 0
'// Failure - non-zero
'//
'// Purpose: Perform main ZTI processing
'//
'//---------------------------------------------------------------------------
Function ZTIProcess()

     iRetVal = Success

     ZTIProcess = iRetval

     Dim objSysInfo, objComputer, strMessage, strDescription, g_strUserName
     g_strUserName = oEnvironment.Item("COMPUTERDESCRIPTION")
     Set objSysInfo = CreateObject("ADSystemInfo")
     Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)

     strDescription = g_strUserName

     objComputer.Description = strDescription
     objComputer.SetInfo

End Function

</script>
</job>

No comments: