Hi,
We could come up with the following steps to complete this request:
- Enable PowerShell in boot images.
- Create a package that copy's Active Directory module files to the boot image, and run it in task sequence.
- Create a PowerShell script that do the following:
Interact with task sequence.
load PowerShell form for prompting computer name selection.
Import Active Directory module, securely connect to Active Directory and check the name against Active Directory.
Set computer name as OSDComputername TS variable (assuming that the name not exists).
PowerShell form script:
######## Close the TS UI temporarily
$TSProgressUI = New-Object -COMObject Microsoft.SMS.TSProgressUI
$TSProgressUI.CloseProgressDialog()
function button ($title,$mailbx, $WF, $TF) {
###################Load Assembly for creating form & button######
[void][System.Reflection.Assembly]::LoadWithPartialName( “System.Windows.Forms”)
[void][System.Reflection.Assembly]::LoadWithPartialName( “Microsoft.VisualBasic”)
#####Define the form size & placement
$form = New-Object “System.Windows.Forms.Form”;
$form.Width = 500;
$form.Height = 150;
$form.Text = $title;
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen;
##############Define text label1
$textLabel1 = New-Object “System.Windows.Forms.Label”;
$textLabel1.Left = 25;
$textLabel1.Top = 15;
$textLabel1.Text = $mailbx;
############Define text box1 for input
$textBox1 = New-Object “System.Windows.Forms.TextBox”;
$textBox1.Left = 150;
$textBox1.Top = 10;
$textBox1.width = 200;
#############Define default values for the input boxes
$defaultValue = “”
$textBox1.Text = $defaultValue;
#############define OK button
$button = New-Object “System.Windows.Forms.Button”;
$button.Left = 360;
$button.Top = 85;
$button.Width = 100;
$button.Text = “Ok”;
############# This is when you have to close the form after getting values
$eventHandler = [System.EventHandler]{
$textBox1.Text;
$form.Close();};
$button.Add_Click($eventHandler) ;
#############Add controls to all the above objects defined
$form.Controls.Add($button);
$form.Controls.Add($textLabel1);
$form.Controls.Add($textBox1);
$ret = $form.ShowDialog();
#################return values
return $textBox1.Text
}
$return= button “Enter Computer Name” “Computer Name”
#################Below variables will get the values that had been entered by the user
$return
#######################
#Import AD Module#
#######################
$C = Get-Credential
import-module activedirectory -force
while (get-adcomputer -filter * -credential $c -server YOUR-DC-NAME | Where-Object { $_.Name -eq ("$return") })
{$return= button “Enter Computer Name” “Computer Name Exist” {break;}}
########## Enter OSDComputername Value To TS
$OSDComputerName = $return
$TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$TSEnv.Value("OSDComputerName") = "$($OSDComputerName)"
$Form.Close()
Here is the detailed article:
http://idanve.blogspot.com/2017/11/verify-computer-name-against-active.html
Note: Non-Microsoft link, just for the reference.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.