*Note : This is part of a series for how I build Windows Enterprise Test environment. *

In this guide, I will walk you through the steps to configure a newly installed Windows 10 machine to join an existing Active Directory domain using PowerShell. The commands for the configuration process will be included in a script and each command will be thoroughly explained to help you understand the process.

By the end of this tutorial, you will have a clear understanding of how to join a Windows 10 machine to an Active Directory domain using PowerShell.


Table of Contents


Update Local Computer Settings

  • Allow use of PowerShell
    Set-ExecutionPolicy RemoteSigned -Confirm:$False
    
  • Computer name
    Rename-Computer -NewName client1
    
  • Network Configuration
    New-NetIPAddress -IPAddress 192.168.1.21 -DefaultGateway 192.168.1.1 -PrefixLength 24 -InterfaceIndex (Get-NetAdapter).InterfaceIndex 
    Set-DnsClientServerAddress -InterfaceIndex (Get-NetAdapter).InterfaceIndex  -ServerAddresses ("192.168.1.10")
    
    • Notes:
      • If you have a DHCP in your environment, you can skip this. But you have to ensure that the client machine and the active diretory can ping each other.
      • Your DNS server/IP should be your Active Directory
      • If you have more than 1 network adapter, get the value of your InterfaceIndex by running this command (below) and take note of the value for your network interface and use it as your InterfaceIndex in the command above .
        (Get-NetAdapter).InterfaceIndex
        

Join Domain

  • In order for this to be successful you must know the active directory admnistrator credentials.
    $Username = "ronwork.com\administrator" 
    $Password = ConvertTo-SecureString "P@55w0rd" -AsPlainText -Force 
    $Credential = New-Object System.Management.Automation.PSCredential($Username, $Password) 
    Add-Computer -DomainName "ronwork.com" -Credential $Credential 
    Add-Computer -DomainName "ronwork.com" -OUPath "OU=Computers,DC=example,DC=com" -Credential $Credential -Restart -Force 
    

Final Script

  • Filename : LocalSettings.ps1

    Set-ExecutionPolicy RemoteSigned -Confirm:$False
    New-NetIPAddress -IPAddress 192.168.1.21 -DefaultGateway 192.168.1.1 -PrefixLength 24 -InterfaceIndex (Get-NetAdapter).InterfaceIndex 
    Set-DnsClientServerAddress -InterfaceIndex (Get-NetAdapter).InterfaceIndex  -ServerAddresses ("192.168.1.10")
    Restart-Computer -Force 
    
  • Filename : joinDomain.ps1

    $Username = "ronwork.com\administrator" 
    $Password = ConvertTo-SecureString "P@55w0rd" -AsPlainText -Force 
    $Credential = New-Object System.Management.Automation.PSCredential($Username, $Password) 
    Add-Computer -DomainName "ronwork.com" -Credential $Credential 
    Add-Computer -DomainName "ronwork.com" -OUPath "OU=Computers,DC=example,DC=com" -Credential $Credential -Restart -Force 
    

Testing and conclusion

Between the execution of these two scripts, the machine will require a restart. Upon successful restart, if the Active Directory is properly configured, and the client machine should be able to join the Active Directiry without any issues.

To verify the setup, you can attempt to log in using the domain users created in the previous step of the guide, Install and Configure Active Directory using PowerShell.