What's New

Joining a Computer to a Domain Using PowerShell


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 = ""
$strPassword = ConvertTo-SecureString "P@55w0rd" -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PsCredential $strUser,

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

12-22-2015 12-38-43 AM
Within the PowerShell Command Line you will call the PowerShell Script within your script folder: %SCRIPTROOT%\BTNHD\JoinDomain.ps1

12-22-2015 12-40-32 AM

About BjTechNews (924 Articles)
An IT guy trying to learn everything about technology and sharing it with you all. I'm a blogger and video blogger who highlights daily news in the tech industry, promoting tips and hacks for fellow techies.

2 Comments on Joining a Computer to a Domain Using PowerShell

  1. Does this use the computer name within MDT 2013?

  2. Excellent Script to use in my Task Sequence to avoid it joining the domain too early on. However you missed out one bit in the last line. Should be
    Add-computer -DomainName $strDomain -Credential $Credentials -OUPath $strOU
    otherwise the variable you defined early for $strOU has no effect.

1 Trackback / Pingback

  1. Deploying a Windows 10 1607 Reference Image with Microsoft Deployment Toolkit 8443 | Stick To The Script!

Leave a Reply

%d bloggers like this: