Quantcast
Channel: Configuration Manager 2007 Operating System Deployment forum
Viewing all articles
Browse latest Browse all 1063

Modifying Active Directory During OSD

$
0
0

I have built a task sequence for installing Windows 7 64-bit. The first step is a VBScript that gathers the computer name, AD domain OU, and computer description. For the computer name and domain OU, I used the built-in task sequence variables OSDComputerName and OSDDomainOUName, and for the computer description, I use a custom TS variable name called ComputerDescription. OSDComputerName and OSDDomainOUName are automatically used by the task sequence and give the computer the correct name and place it in the OU I specify.

However, when I run a different VBScript (after the OS and drivers are applied and the computer reboots), it does not set the computer description using the TS variable I set before the install started. The script works fine outside the task sequence and also works when I run it from a command prompt during the same point in the TS, but it just doesn't work when ran as a program. Initially I thought it might be that my user account running the task sequence didn't have permissions on AD, so I added it to our System Installers group, which does have permissions. Still nothing.

Here is the snippet of code that saves the computer description from the first script:

DoUntil strAnswer1 = "Y"
	computerDescription = InputBox ("Enter the computer description for storing in active directory. "& _"If you don't know the user this computer is being assigned, please enter a generic description."& _
					Chr(13), "Computer Description",,250,250)
	strAnswer1 = InputBox (computerDescription & Chr(13) & Chr(13) & "will be the computer description. Enter Y to continue "& _"with this or N to enter it again.", "Computer Description",,250,250)
	strAnswer1 = UCase(strAnswer1)Loop

OTS ("ComputerDescription") = computerDescription

 

Here is the script that runs after the reboot that is supposed to find the computer account and set the description (with a few modifications to hide domain names):

Set OTS = CreateObject ("Microsoft.SMS.TSEnvironment")Set wshShell = WScript.CreateObject( "WScript.Shell" )
strComputer = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
strDescription = OTS("ComputerDescription")Const ADS_SCOPE_SUBTREE = 2Set objConnection = CreateObject("ADODB.Connection")Set objCommand =  CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 

objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://dc=domain,dc=local' WHERE objectCategory='computer' and name = '"& strComputer & "'"Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
DoUntil objRecordSet.EOF
   strDN = objRecordSet.Fields("distinguishedName").Value
   objRecordSet.MoveNextLoopSet objComputer = GetObject("LDAP://"& strDN)OnErrorResumeNext
objComputer.Put "description",strDescription
objComputer.SetInfo

I hope this all makes sense. Please ask any questions for clarification. The script works fine outside the task sequence but doesn't work when in the task sequence (except when I manually run it from a command prompt, which is not an option). The variable ComputerDescription does contain the string set in the first script, I have tested that also. I also have another script for when I migrate XP to Windows 7 that is supposed to move the computer account from the XP OU to the Windows 7 OU, and it doesn't work either. I suspect solving one will solve the other. Thanks.

Jeff


Viewing all articles
Browse latest Browse all 1063

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>