How to join an Active Directory domain with PowerShell DSC

To support me, you can subscribe to the channel, share and like the videos, disable your ad blocker, purchase my 3D plans, or make a donation or subscribe on Ko-Fi. Thank you!

Hello,

Joining an Active Directory domain with PowerShell DSC

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) 

PowerShell DSC code to join a domain

# Installing the DSC modules.
$package = @( 'ComputerManagementdsc' )
Install-Package $package -Force -Source psgallery
# Identifiers for installing the domain and for DSRM
$passwd = ConvertTo-SecureString 'P@ssword' -AsPlainText -Force
$id = New-Object System.Management.Automation.PSCredential('domaine\tech1',$passwd)
# Enable Winrm
Enable-PSRemoting -Force -SkipNetworkProfileCheck
# Authorise scripts
Set-ExecutionPolicy RemoteSigned -Force
# DSC engine configuration
[DSCLocalConfigurationManager()]
LCMConfig configuration
{
Node localhost
{
settings
{
ActionAfterReboot = 'ContinueConfiguration'
ConfigurationMode = 'ApplyOnly'
RebootNodeIfNeeded = $true
}
}
}
LCMConfig
Set-DscLocalConfigurationManager -ComputerName localhost -Force -Verbose -path .\LCMConfig
# To avoid errors when using identifiers in DSC
$configData = @{
AllNodes = @(
@{
NodeName = 'localhost';
PSDscAllowPlainTextPassword = $true
}
)
NonNodeData = $data
}
# Creating the DSC configuration
Demo-Junction configuration
{
param (
[string[]]$NodeName = 'localhost',
[Parameter(Mandatory)][string]$MachineName,
[Parameter(Mandatory)][string]$DomainName,
[Parameter(Mandatory)][string]$OU
)
# Import DSC resources
Import-DscResource -Module ComputerManagementDSC
Node $NodeName {
Computer NewNameAndWorkgroup {
Name = $MachineName
DomainName = $DomainName
Credential = $id
JoinOU = $OU
}
}
}
# Create the DSC configuration file
Demo-Junction -MachineName PC-DSC -DomainName domaine.tld -OU 'ou=computers,dc=domain,dc=tld' -ConfigurationData $configData
# Application of the DSC file
Start-DscConfiguration -ComputerName localhost -Wait -Force -Verbose -path .\Demo-Junction -Debug

Video : How to join an Active Directory domain with PowerShell DSC

Play

Related links