Custom OSD Scripting - Larger Front End Script
So I've shown an example of a simple script and how to accept data and store it in a TS variable. Here I am going to post two scripts. The first VB Script will copy some files to the target machines, and the second is the Larger Front End Script. Items that will be collected are
Computer Name: - will set the native OSDComputerName variable. After setting this variable, no other action is needed to set the computer name.
User Name: - will set the custom OSDUserName variable.
Business Unit / OU: - this will set the native OSDDomainOUName. I have theee radio buttons for three different biasness units, basically three different OU structures. You can just consolidate this or expand on this as needed.
Managed / Un-Managed: - this will set the custom OSDManaged variable and aid in adding the computer object to security groups. Think of this as computer roles - you can basically change these to anything you may need to trigger and action off of later in the back end script.
Description: this sets the custom OSDComputerDescription variable and aids in giving the computer object a description as well as set the local computer description.
First thing first - OU's. The way I have chosen to populate the available OU's is to manually type these out in a text file (actually three, one for each business unit) and copy these text files to the local machine for retrieval. I understand that you could pragmatically populate this list but this works out better for me and is quite simple, clean, and effective. Each text file is in the format of
OU1 Workstations
LDAP://OU=OU1,OU=Workstations,DC=domain,DC=com
OU1 Laptops
LDAP://OU=OU1,OU=Laptops,DC=domain,DC=com
and so on. The first line is the label that will show up on the .HTA script and the second line is the value that will be placed in the OSDDomainOUName variable. Once created add the files to the Scripts folder under the MDT tollkit package.
To copy these files to the target machine, create the following script, add it to your task sequence (I have mine as the first task under Preinstall - New Computer Only), and also copy it to the Scripts folder under the MDT tollkit package..
Set sho = Wscript.CreateObject("Wscript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
strCurrentDir = Left(Wscript.ScriptFullName, (InstrRev(Wscript.ScriptFullName, "\") -1))
Set strSysFolder = FSO.GetSpecialFolder(1) 'get system32 folder
'Copy the dll to the system folder
FSO.CopyFile strcurrentdir & "\bunit1.txt",strSysFolder & "\"
FSO.CopyFile strcurrentdir & "\bunit2.txt",strSysFolder & "\"
FSO.CopyFile strcurrentdir & "\bunit3.txt",strSysFolder & "\"
wscript.quit
This should copy the file(s) down to the x:\windows\system32 folder on your target machine.
Here is the .HTA script's output
And here is the script.
<html>
<head>
<title>Front End Scripts</title>
<HTA:APPLICATION
APPLICATIONNAME="OSD GATHER"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
BORDER="thin"
>
</head>
<script language="vbscript" type="text/vbscript">
Sub Window_onLoad
window.resizeTo 430,590
End Sub
Sub ButtonFinishClick
Dim OU
OU = AvailableOU.Value
For Each objButton in managed
If objButton.Checked Then
strManaged = objButton.Value
End If
Next
Dim compdescription
compdescription = computerdescription.Value
SET env = CreateObject("Microsoft.SMS.TSEnvironment")
env("OSDComputerName") = computername.Value
env("OSDUserName") = Username.Value
env("OSDDomainOUName") = OU
env("OSDComputerDescription") = compdescription
env("OSDManaged") = strManaged
window.Close
End Sub
Sub OU
For Each objOption in AvailableOU.Options
objOption.RemoveNode
Next
For Each objButton in Bunit
If objButton.Checked Then
strFileName = objButton.Value
End If
Next
ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile ("x:\windows\system32\" & strFileName, ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
strValue = objFile.ReadLine
Set objOption = Document.createElement("OPTION")
objOption.Text = strLine
objOption.Value = strValue
AvailableOU.Add(objOption)
Loop
objFile.Close
End Sub
</script>
<body>
<p>Computer Name:</p>
<input type=text id="computerName" name=computerName size=40><br />
<p>User Email:</p>
<input type=text id="UserName" name=UserName size=40><br />
<p>Buisness Unit:<p>
<input type="radio" name="Bunit" value="bunit1.txt" onClick="OU">Bunit1
<input type="radio" name="Bunit" value="Bunit2.txt" onClick="OU">Bunit2
<input type="radio" name="Bunit" value="Bunit3.txt" onClick="OU">Bunit3<br /><br />
<select size="7" name="AvailableOU" style="width:350"></select><br /><br />
<input type="radio" name="managed" value="(LM)">Managed
<input type="radio" name="managed" value="(UM)">Un-Managed<br /><br />
<p>Computer Description:</p>
<input type=text id="computerdescription" name=computerdescription size=40><br /><br />
<button accesskey=N type=submit id=buttonFinish onclick=ButtonFinishClick ><U>F</U>inish</button>
</body>
</html>
When you click on any of the Business Unit radio buttons the script will look for the corresponding OU text file and populate the list box with the OU data. Obviously you can scale this to meet your needs.
So basically just like on the previous posts simple script, all we are doing is gathering some data - although more of it and through different web application components, and then assigning this data to to different TS variables. Also once complete just add this to the MDT Scripts directory, and also to the task sequence as we did before. Also do not forget to update your Distribution Points.
I did not comment much in this script, I apologize for that. If anyone has specific questions please let me know.
Next I will provide the back end script which performs all of the work.
neilp