Check Computer Name using DoesComputerExist

Mar 15, 2010 at 2:27 PM
Edited Mar 16, 2010 at 7:30 PM

Hello,

I have two custom panes I have added to the Deployment Wizard immediatly after the credentials pane.  The first one allows the user to enter information into several custom fields.  These are setup as custom properties in the customsettings.ini.  The second is basically a verification page.  On this page I have an autogenerated computer name based on input from the first page.  I'm trying to figure out how to have MDT check the autogenerate computer name against Active Directory to be sure it doesn't exist.  If it does exist, I need it to prompt the user to go back and make changes.  I have the MDT Web Services setup and working, but I'm not sure how/where to place the code.  Has anyone set up something similar?  Thanks.

 

UPDATE:  I've got it calling the script, but I'm getting "ZTI ERROR - Unhandled error returned by ZTIDoesComputerExist Object variable not set (91)"  Any thoughts??

Mar 17, 2010 at 7:37 PM
Edited Mar 17, 2010 at 7:38 PM

UPDATE!  I've finally figured out where I was going wrong.  The "91" error was a simple typo.  So here is how I have it working if anyone is interested:

 

Step 1: Update the customsettings.ini by adding in my custom properties.  In this case I used "myServerName".  I also added a "strServerExists" property.  Next I added the following section to the customsettings.ini.

[DoesComputerExist]
WebService=http://mywebserver/DeploymentWebservice/AD.asmx/DoesComputerExist
Parameters=myServerName
myServerName=ComputerName

Step 2: Create a ZTIDoesComputerExist.wsf in your Deploy$\scripts folder

<job id="ZTIDoesComputerExist" prompt="no">
 <?job error="false" debug="false" ?>
 <script language="VBScript" src="ZTIUtility.vbs"/>
 <script language="VBScript" src="ZTIDataAccess.vbs"/>
 <script language="VBScript">
' //***************************************************************************
' // ***** Script Header *****
' //
' // File:      ZTIDoesComputerExist.wsf
' //
' // Purpose:   Check to see if the computer name exists in Active Directory
' //
' // Usage:     cscript ZTIDoesComputerExist [/debug:true]
' //
' //
' // Customer History:
' // 1    MK    01/18/2009  changed to use Webservice instead of AD Scripting
' //
' // ***** 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()

 Dim oService, oXML, strMyServer, sResult
 iRetVal = Success

 oLogging.CreateEntry "DOES COMPUTER EXIST: Processing Does Computer Exist in AD routine", LogTypeInfo


 ' Create the web service instance
 Set oService = New WebService
 oService.iniFile = "customsettings.ini"
 oService.SectionName = "DoesComputerExist"
 
 strMyServer = oEnvironment.item("myServerName")
 
 ' Make the web service call
 Set oXML = oService.Query
 If oXML Is Nothing Then
  oLogging.CreateEntry "Unable to call DoesComputerExist web service.", LogTypeWarning
  MsgBox "Could not verify computer name against AD!  Please contact your Administrator."
  sResult = 0
 Else
  oXML.setProperty "SelectionNamespaces", "xmlns:mk='http://maikkoster.com/Deployment'"
  If UCase(oXML.SelectSingleNode("mk:boolean").Text) = "TRUE" Then
   oLogging.CreateEntry "Computer exists in Active Directory!", LogTypeInfo
   MsgBox "Computer account already exists!! Please use the back arrow to return to the previous screen and make the necessary changes."
   sResult = True
   iRetVal = Success
  Else
   oLogging.CreateEntry "Computer does NOT exist in Active Directory!", LogTypeInfo
   sResult = False
  End If
 End If

 oEnvironment.item("strServerExists") = sResult
 
 ZTIProcess = iRetVal

End Function

 </script>
</job>

<!--b error="false" debug="false"-->Step 3:  Add the following function to the DeployWiz_Validation.vbs

Function ValidateComputerAccount

 Dim oItem
 Dim sCmd

 sCmd = "wscript.exe Z:\scripts\ZTIDoesComputerExist.wsf"
 oItem = oSHell.Run(sCmd, , true)
 
 If oEnvironment.item("strServerExists") <> True Then
  ButtonNext.disabled = True
 Else
  ButtonNext.disabled = False
 End If
 
 
End Function

Step 4:  On my "Verify configuration" Wizard pane, I added a new Initialization Setting pointing to the ValidateComputerAccount Function.

That is what did the trick.  Now I have my initial Configuration screen where the user enters data that fills the custom properties (State, branch number, etc.), with code that autogenerates a computer name.  When the user clicks on next, the second pane (Verify configuration) checks the computer name against AD, and if it exists, pops up a warning and disables the next button.

Coordinator
Mar 18, 2010 at 1:26 PM

Very nice. Thanks for sharing this.

 

Maik

Mar 18, 2010 at 1:36 PM

No problem.  Thank you for the Web Service.  Have you had a chance to look at my other post about the SetComputerDescription failing?  I still can't get that to work.

Eddie