Advertisements
What's New

Joining a Computer to a Domain Using PowerShell

windows_powerShell_wp_header

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

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

Advertisements
About BjTechNews (911 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.

1 Comment on Joining a Computer to a Domain Using PowerShell

  1. 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: