Skip to content
Posts Jul 13, 2023 2 min read

Join a Workstation to Active Directory with Shell and PowerShell

A comparison of efficient one-liner commands in both Shell and PowerShell for joining workstations to Active Directory domains with proper credential handling and automatic restart functionality.

Join a Workstation to Active Directory with Shell and PowerShell

In this blog post, we will showcase concise and efficient commands that you can use in both Shell and PowerShell to join a workstation to Active Directory. These one-liner commands are practical for both quick use cases and scripting.

Shell

The following one-liner in Shell can join a workstation to Active Directory. It first invokes PowerShell to utilize its more sophisticated handling of secure credentials.

powershell -Command "& {$password = ConvertTo-SecureString 'thepassword' -AsPlainText -Force; $credential = New-Object System.Management.Automation.PSCredential ('domain\username', $password); Add-Computer -DomainName 'thedomainname' -Credential $credential -Restart -Force}"

In this command, replace ’thepassword’, ‘domain\username’, and ’thedomainname’ with the actual password, domain username, and domain name, respectively. After execution, the workstation will be forced to restart to apply the changes.

PowerShell

You can also use PowerShell directly to achieve the same result. The following command is similar to the Shell command but is run natively in PowerShell:

& {$password = ConvertTo-SecureString 'thepassword' -AsPlainText -Force; $credential = New-Object System.Management.Automation.PSCredential ('domain\username', $password); Add-Computer -DomainName 'thedomainname' -Credential $credential -Restart -Force}

Like with the Shell command, you need to replace ’thepassword’, ‘domain\username’, and ’thedomainname’ with the actual password, domain username, and domain name, respectively. The workstation will restart after this command is executed.

Connected Reading

Related entries

Chosen from shared tags, categories, and nearby section context.

Discovery Layer

Connected Memory

A focused relationship view around this entry, using shared categories and tags.

Categories 0
Tags 0
Posts 0