Custom OSD Scripting – Simple Front End Script.
I currently use two Front end scripts in my OSD process, one to collect some user credentials and the second to collect the rest of the computer/user/other info. This is the first of those. The script prompts for a user name and password which are both then stored in two “custom task sequence” variables. Refer to the article “About Task Sequence Variables” for more information about TS variables. This script is a good simple example of both the framework of an .HTA script, the invoking of the Task Sequence environment, and the creation of Task Sequence variables. Once set these variables will exist throughout the life cycle of the running task sequence – quite brilliant.
I use this particular script to gather some credentials that I can later pass to a back end script that will "do some stuff" with the computer object in AD.
<html>
<head>
<title>Admin Account</title>
<HTA:APPLICATION
APPLICATIONNAME="Log IN"
SCROLL="No"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
BORDER="thin"
>
</head>
<script language="vbscript" type="text/vbscript">
Sub Window_onLoad
window.resizeTo 320,260
End Sub
Sub ButtonFinishClick
SET env = CreateObject("Microsoft.SMS.TSEnvironment")
env("OSDAdminUserName") = AdminUserName.Value
env("OSDAdminPassword") = AdminPassword.Value
window.Close
End Sub
</script>
<body>
<p>Admin User:</p>
<input type=text id="AdminUserName" name=AdminUserName size=40><br /><br />
<p>Password:</p>
<input type=password id="AdminPassword" name=AdminPassword size=40><br /><br />
<button accesskey=N type=submit id=buttonFinish onclick=ButtonFinishClick ><U>F</U>inish</button>
</body>
</html>
So the majority of this is a simple .HTA stuff, basic HTML. What I would like to focus on is everything between Sub ButtonFinishClick and the following End Sub (the text in Red).
1. SET env = CreateObject("Microsoft.SMS.TSEnvironment")
2. env("OSDAdminUserName") = AdminUserName.Value
3. env("OSDAdminPassword") = AdminPassword.Value
Line number 1. is establishing a connection with the Task Sequence environment.
Line number 2. and 3. both create a new TS variable and assign it a value. So on Line 2. the TS variable name is OSDAdminUserName and the value is whatever was entered into the AdminUserName text box.
As you will see in a later post, on the back end script we will simply invoke the TS environment once again using line 1. and then will have access to the data stored in each of these TS variables for use in said back end script.
What to do with these scripts once completed?
Adding .HTA Support to the Boot Image.
Natively the CM boot images do not support .HTA files. One way to insert this capability into your boot images is to create a custom boot image using MDT. If you have the Microsoft Deployment Toolkit integrated with CM then you can simply right click on "Boot Images" node and then click on "Create Boot Image using Microsoft Deployment", this will begin the Wizard. If you are not using the MDT then you can find some info on how to customize the here.
Making the script available to the TS.
What I have done with the script is to place it in the Scripts folder of the MDT Toolkit package (this was created when importing the MDT task sequence). Make sure you update the distribution points after this. Next I added a command line under the "New Computer Only" group of the task sequence with a command line of
%deployroot%\scripts\admincridentials.hta
Once this is done you should be good to go.
neilp