How to join an Active Directory domain using PowerShell
3 min read · Updated 10 November 2021
Hello,
Joining an Active Directory domain using PowerShell
Presentation of different alternatives for joining an Active Directory domain:
How to join an Active Directory domain with System Properties (1/9)
Best domain joining practices - Delegation and pre-staging (2/9)
How to join an Active Directory domain using the Settings Menu (3/9)
How to join an Active Directory domain using PowerShell (4/9)
How to join an Active Directory domain with djoin (offline) (5/9)
How to join an Active Directory domain with netdom (6/9)
How to join an Active Directory domain with DSC (7/9)
How to join an Active Directory domain with ICD (8/9)
How to join an Active Directory domain with MDT (9/9)
Joining the Active Directory in PowerShell
Code PowerShell
## On the domain controller.# When using pre-staging, it may be necessary to also delegate the creation of the object in the domain and not just the join to the domain.# Following a change to the domain junction reinforcement, you must be a domain administrator or the owner of the computer object to join the computer to the domain# https://support.microsoft.com/en-us/topic/kb5020276-netjoin-domain-join-hardening-changes-2b65a0f3-1f4c-42ef-ac0f-1caaf421baf8
# Name of the OU Computers$OUOrdinateursName = 'Ordinateurs'# Distinguished name of the domain$DomaineDN = (Get-ADDomain).distinguishedname
# Allow a group to join a computer to the domain on an OU. With inherited rights :$OrdinateursOU = "ou=$OUOrdinateursName,$DomaineDN"dsacls $OrdinateursOU /I:S /G $GPName":WS;Validated write to DNS host name;computer"dsacls $OrdinateursOU /I:S /G $GPName":WS;Validated write to service principal name;computer"dsacls $OrdinateursOU /I:S /G $GPName":CA;Reset Password;computer"dsacls $OrdinateursOU /I:S /G $GPName":WP;Account Restrictions;computer"
# Add creation rights for the computer in the OUdsacls $OrdinateursOU /I:T /G $GPName":CC;computer"
## On the workstation to join the domain# You can define the destination OU and rename the workstation.$PCName = 'pc-PoSH$domaine = 'domaine.tld'$ou = 'Ordinateurs'$oupath = 'ou={2},dc={0},dc={1}' -f ($domaine.split('.') + $ou)
$param = @{ DomainName = $domaine NewName = $NomPC Credential = get-credential OUPath = $oupath Restart = $true}Add-Computer @paramVideo : How to join an Active Directory domain using PowerShell
Related links
- Configuration
How to join an Active Directory domain using the netdom command
Join an Active Directory domain with the netdom command
1 min read
- Configuration
How to join an Active Directory domain with djoin (offline)
Joining an Active Directory domain with djoin (offline), so without the workstation having access to a domain controller
1 min read
- Configuration
How to join an Active Directory domain using the Settings Menu
Join an Active Directory domain with the Settings Menu
1 min read
- Configuration
How to add and change languages in Windows 10 and Windows 11
Add a language to Windows 10 and Windows 11, then choose the system display language, with a demonstration video.
1 min read
- Configuration
Services and the services console on Windows
A video presenting services and the Windows services console (start-up mode, service properties and user services)
1 min read
- Configuration
The difference between a printer and a printing device
A video explaining the difference between a printer and a printing device in Windows 10, Windows 11 and Windows Server.
1 min read