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.
PowerShell script to add a Windows device to the domain
123456789101112131415
$domain = “Your-domain-name" $username = “$domain\domain-user” #user name with privileges to add a device to the $domain $password = “********” |ConvertTo-SecureString –asPlainText –Force #password for the above user $user2 = “Administrator” #administrator account of the device $pass2 = “**********” #password for $user2 $lcred = New-object –TypeName System.Management.Automation.PSCredential -ArgumentList ($user2, $pass2) $credential = New-object –TypeName System.Management.Automation.PSCredential -ArgumentList ($username, $password) Add-Computer –DomainName $domain –Credential $credential –LocalCredential $lcred –Restart –Force
- The Add-Computer command generally takes the following syntax:
Add-Computer
[-ComputerName <String[]>]
[-LocalCredential <PSCredential>]
[-UnjoinDomainCredential <PSCredential>]
[-Credential <PSCredential>]
[-DomainName] <String>
[-OUPath <String>] [-Server <String>]
[-Unsecure]
[-Options <JoinOptions>]
[-Restart]
[-PassThru]
[-NewName <String>]
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$domain = “Your-domain-name" $username = “$domain\domain-user” #user name with privileges to add a device to the $domain $password = “********” |ConvertTo-SecureString –asPlainText –Force #password for the above user $user2 = “Administrator” #administrator account of the device $pass2 = “**********” #password for $user2 $lcred = New-object –TypeName System.Management.Automation.PSCredential -ArgumentList ($user2, $pass2) $credential = New-object –TypeName System.Management.Automation.PSCredential -ArgumentList ($username, $password) Add-Computer –DomainName $domain –Credential $credential –LocalCredential $lcred –Restart –Force |
- The Add-Computer command generally takes the following syntax:
Add-Computer
[-ComputerName <String[]>]
[-LocalCredential <PSCredential>]
[-UnjoinDomainCredential <PSCredential>]
[-Credential <PSCredential>]
[-DomainName] <String>
[-OUPath <String>] [-Server <String>]
[-Unsecure]
[-Options <JoinOptions>]
[-Restart]
[-PassThru]
[-NewName <String>]
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
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.