次の方法で共有


How to Use HTA file to provide a Computer Name and OU name in OSD

Hi Folks,

One of the most common requirements at the time of OSD is to have the option to specify a custom machine name during the deployment.
There are multiple ways to accomplish this. I am demonstrating the approach of using a simple HTA file to achieve this.Before we discuss about the steps required for this objective, let us discuss briefly about HTA files and setting up task sequence variables:

HTA Files:

HTML Applications (HTAs) provide a way to wrap your scripts up in a graphical user interface. For more information on scripting HTA files please refer to following links:

https://technet.microsoft.com/en-us/library/ee692662.aspx
https://technet.microsoft.com/en-us/library/ee692768.aspx?f=255&MSPPError=-2147217396

 Task Sequence Variables:

We can create, get, and set task sequence variables in a running task sequence by using the task sequence environment COM automation object (Microsoft.SMS.TSEnvironment). In the example below I have used this object to set the OSDComputerName and OSDDomainOUName variables:

    1: SET env = CreateObject("Microsoft.SMS.TSEnvironment") 
    2: env("OSDComputerName") = OSDcomputername.Value 
    3: env("OSDDomainOUName") = computerOUName.Value 

This can also be set using powershell:

    1: $OSDEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment
    2: $OSDENV.Value("OSDComputerName")
    3: $OSDENV.Value("OSDDomainOUName")

Please refer to following article to know more about Task Sequence Variables in a Running Configuration Manager Task Sequence:

https://msdn.microsoft.com/en-us/library/cc145669.aspx 

 

Using HTA file to provide Computer Name during task sequence:

I have used a simple task sequence in this example where I have left the Domain OU name blank(for the next example where I provide the option to enter an OU name as well). I am not using any custom unattend.xml file:

clip_image002

  1.) Create a package with the HTA file:

image

 

2.) Modify the boot image to include this package and add a prestart command to it:

image

To know more about using Prestart command please refer to following article:

https://blogs.msdn.com/b/steverac/archive/2015/04/22/power-belongs-to-you-the-osd-prestart-command.aspx

3.) Enable HTA support in boot image. This can be done by going to the Optional components tab and then clicking on the yellow start on the lower right had corner to bring up the complete list:

image

In case you wish to enable powershell support, please choose that as well

4.) Confirm these settings (click apply and ok), re-distribute the  boot image to DP

5.)  Boot up a new machine (I used boot media during my test, however we can use PXE boot as well)

6.)  Click Next to start the task sequence wizard:

 

image

7.) This will execute the prestart command and bring up the HTA file:

image

8.) Select the task sequence:

image

9.) We can see that the HTA file execution was completed successfully:

image

10.) We see that the Task Sequence writes the data to unattend.xml file, this consists of the Task Sequence variable we set as part of HTA file in the beginning:

image

11.) We can open the Unattend.xml in WINPE and verify the name has been set:

image

12.) The machine will reboot and after sometime get into full OS. We can verify from the netsetup.log that at the time of install the value specified was picked up for machine name:

image

 

Using HTA file to provide Computer Name and OU Name during task sequence:

Same steps can be performed to provide with an OU name as well during the install process. Complete Distinguished Name of the OU needs to be provided for this to work:

image

At the time of OSD this value is appended to the default unattend.xml file:

 

Similarly we have a list of task sequence variables which can be set during the Install Process. Please refer to following TechNet article for the list of variables:

https://technet.microsoft.com/en-au/library/hh273365.aspx

 

Hope this helps!

Disclaimer: This posting is provided "AS IS" with no warranties and confers no rights

OUName.zip

Comments

  • Anonymous
    November 17, 2015
    Excellent Blog!!
  • Anonymous
    November 20, 2015
    That's promising !!!. Nice research