Category filter

Script to add Windows devices to Active Directory domain

Adding Windows devices to an Active Directory domain is no more a hassle. You can get it done quickly by creating PowerShell scripts to be executed from the Hexnode portal. It adds the device to the specified domain without requiring direct access to the device.


The Sample Scripts provided below are adapted from third-party Open-Source sites.

Jump To

PowerShell script to add a Windows device to the domain

  • The Add-Computer command generally takes the following syntax:


    [-ComputerName <String[]>]

    [-LocalCredential <PSCredential>]

    [-UnjoinDomainCredential <PSCredential>]

    [-Credential <PSCredential>]

    [-DomainName] <String>

    [-OUPath <String>] [-Server <String>]


    [-Options <JoinOptions>]



    [-NewName <String>]





    Depending on your need, you may alter the attributes. For instance,

    Add-Computer -DomainName domainname –OUPath "OU=HexnodeOU CN=Users, DC=Hexnode,DC=local"

    This command specifies the organizational unit for creating the new account and adds the local computer to the domain specified as domainname.

  • The Windows 10 Home editions do not support domain-join. Hence, make sure the devices permit domain-joining before executing the script.

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository