Site icon BTNHD

Joining a Computer to a Domain Using PowerShell

Advertisements

Using PowerShell scripts within a task sequence provides more flexibility than using the CustomSettings.ini file to join a computer to a domain. The parameters of the CustomSettings.ini file are common to any deployment you perform. That’s why creating a custom PowerShell script to join your domain will be customize to only your environment, so the security risk is very low.

Here is the code to join a domain using PowerShell:


$strUser = "bjtech\Administrator"
$strDomain = "bjtech.edu"
$strPassword = ConvertTo-SecureString "P@55w0rd" -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PsCredential $strUser,
$strPassword
$strOU = "OU=STAGING,DC=LOCAL,DC=BJTECH,DC=EDU"

Add-computer -DomainName $strDomain -Credential $Credentials

Once you have created your *.ps1 file and copy it to the script folder under your deployment share. You will then haveto call it within your Task sequence. I placed my PowerShell script command in the “Custom Task Node”. Open your Task Sequence > Click on Add > General > Run PowerShell Script


Within the PowerShell Command Line you will call the PowerShell Script within your script folder: %SCRIPTROOT%\BTNHD\JoinDomain.ps1


Exit mobile version