Skip to content

Commit aa0f240

Browse files
lindakupsdwheeler
andauthored
Update Add-Computer.md with a new example to join a domain with a new name (MicrosoftDocs#11427)
* Update Add-Computer.md Add an example to rename and domain join in one operation and use the Domain Join options parameter correctly. * Editorial changes --------- Co-authored-by: Sean Wheeler <[email protected]>
1 parent 8d229c1 commit aa0f240

File tree

1 file changed

+69
-15
lines changed

1 file changed

+69
-15
lines changed

reference/5.1/Microsoft.PowerShell.Management/Add-Computer.md

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Commands.Management.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Management
5-
ms.date: 09/30/2021
5+
ms.date: 09/25/2024
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/add-computer?view=powershell-5.1&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
title: Add-Computer
@@ -18,17 +18,17 @@ Add the local computer to a domain or workgroup.
1818

1919
```
2020
Add-Computer [-ComputerName <String[]>] [-LocalCredential <PSCredential>]
21-
[-UnjoinDomainCredential <PSCredential>] -Credential <PSCredential> [-DomainName] <String> [-OUPath <String>]
22-
[-Server <String>] [-Unsecure] [-Options <JoinOptions>] [-Restart] [-PassThru] [-NewName <String>] [-Force]
23-
[-WhatIf] [-Confirm] [<CommonParameters>]
21+
[-UnjoinDomainCredential <PSCredential>] -Credential <PSCredential> [-DomainName] <String>
22+
[-OUPath <String>] [-Server <String>] [-Unsecure] [-Options <JoinOptions>] [-Restart] [-PassThru]
23+
[-NewName <String>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
2424
```
2525

2626
### Workgroup
2727

2828
```
29-
Add-Computer [-ComputerName <String[]>] [-LocalCredential <PSCredential>] [-Credential <PSCredential>]
30-
[-WorkgroupName] <String> [-Restart] [-PassThru] [-NewName <String>] [-Force] [-WhatIf] [-Confirm]
31-
[<CommonParameters>]
29+
Add-Computer [-ComputerName <String[]>] [-LocalCredential <PSCredential>]
30+
[-Credential <PSCredential>] [-WorkgroupName] <String> [-Restart] [-PassThru] [-NewName <String>]
31+
[-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
3232
```
3333

3434
## DESCRIPTION
@@ -67,7 +67,7 @@ This command adds the local computer to the Workgroup-A workgroup.
6767
Add-Computer -DomainName Domain01 -Server Domain01\DC01 -PassThru -Verbose
6868
```
6969

70-
This command adds the local computer to the Domain01 domain by using the Domain01\DC01 domain
70+
This command adds the local computer to the Domain01 domain by using the `Domain01\DC01` domain
7171
controller.
7272

7373
The command uses the **PassThru** and **Verbose** parameters to get detailed information about the
@@ -85,7 +85,15 @@ the organizational unit for the new accounts.
8585
### Example 5: Add a local computer to a domain using credentials
8686

8787
```powershell
88-
Add-Computer -ComputerName Server01 -LocalCredential Server01\Admin01 -DomainName Domain02 -Credential Domain02\Admin02 -Restart -Force
88+
$addComputerSplat = @{
89+
ComputerName = 'Server01'
90+
LocalCredential = 'Server01\Admin01'
91+
DomainName = 'Domain02'
92+
Credential = 'Domain02\Admin02'
93+
Restart = $true
94+
Force = $true
95+
}
96+
Add-Computer @addComputerSplat
8997
```
9098

9199
This command adds the Server01 computer to the Domain02 domain. It uses the **LocalCredential**
@@ -97,7 +105,15 @@ and the **Force** parameter to suppress user confirmation messages.
97105
### Example 6: Move a group of computers to a new domain
98106

99107
```powershell
100-
Add-Computer -ComputerName Server01, Server02, localhost -DomainName Domain02 -LocalCredential Domain01\User01 -UnjoinDomainCredential Domain01\Admin01 -Credential Domain02\Admin01 -Restart
108+
$addComputerSplat = @{
109+
ComputerName = 'Server01', 'Server02', 'localhost'
110+
DomainName = 'Domain02'
111+
LocalCredential = 'Domain01\User01'
112+
UnjoinDomainCredential = 'Domain01\Admin01'
113+
Credential = 'Domain02\Admin01'
114+
Restart = $true
115+
}
116+
Add-Computer @addComputerSplat
101117
```
102118

103119
This command moves the Server01 and Server02 computers, and the local computer, from Domain01 to
@@ -112,7 +128,14 @@ domain. It uses the **Restart** parameter to restart all three computers after t
112128
### Example 7: Move a computer to a new domain and change the name of the computer
113129

114130
```powershell
115-
Add-Computer -ComputerName Server01 -DomainName Domain02 -NewName Server044 -Credential Domain02\Admin01 -Restart
131+
$addComputerSplat = @{
132+
ComputerName = 'Server01'
133+
DomainName = 'Domain02'
134+
NewName = 'Server044'
135+
Credential = 'Domain02\Admin01'
136+
Restart = $true
137+
}
138+
Add-Computer @addComputerSplat
116139
```
117140

118141
This command moves the Server01 computer to the Domain02 and changes the machine name to Server044.
@@ -124,28 +147,44 @@ permission to join the computer to the Domain02 domain.
124147
### Example 8: Add computers listed in a file to a new domain
125148

126149
```powershell
127-
Add-Computer -ComputerName (Get-Content Servers.txt) -DomainName Domain02 -Credential Domain02\Admin02 -Options Win9xUpgrade -Restart
150+
$addComputerSplat = @{
151+
ComputerName = (Get-Content Servers.txt)
152+
DomainName = 'Domain02'
153+
Credential = 'Domain02\Admin02'
154+
Options = 'Win9xUpgrade'
155+
Restart = $true
156+
}
157+
Add-Computer @addComputerSplat
128158
```
129159

130160
This command adds the computers that are listed in the `Servers.txt` file to the Domain02 domain. It
131161
uses the **Options** parameter to specify the **Win9xUpgrade** option. The **Restart** parameter
132-
restarts all of the newly added computers after the join operation completes.
162+
restarts all the newly added computers after the join operation completes.
133163

134164
### Example 9: Add a computer to a domain using predefined computer credentials
135165

136166
This first command should be run by an administrator from a computer that is already joined to
137167
domain `Domain03`:
138168

139169
```powershell
140-
New-ADComputer -Name "Server02" -AccountPassword (ConvertTo-SecureString -String 'TempJoinPA$$' -AsPlainText -Force)
170+
$newADComputerSplat = @{
171+
Name = "Server02"
172+
AccountPassword = (ConvertTo-SecureString -String 'TempJoinPA$$' -AsPlainText -Force)
173+
}
174+
New-ADComputer @newADComputerSplat
141175
142176
# Then this command is run from `Server02` which is not yet domain-joined:
143177
144178
$joinCred = New-Object pscredential -ArgumentList ([pscustomobject]@{
145179
UserName = $null
146180
Password = (ConvertTo-SecureString -String 'TempJoinPA$$' -AsPlainText -Force)[0]
147181
})
148-
Add-Computer -Domain "Domain03" -Options UnsecuredJoin,PasswordPass -Credential $joinCred
182+
$addComputerSplat = @{
183+
DomainName = "Domain03"
184+
Options = 'UnsecuredJoin', 'PasswordPass'
185+
Credential = $joinCred
186+
}
187+
Add-Computer @addComputerSplat
149188
```
150189

151190
This combination of commands creates a new computer account with a predefined name and temporary
@@ -154,6 +193,21 @@ the predefined name joins the domain using only the computer name and the tempor
154193
The predefined password is only used to support the join operation and is replaced as part of normal
155194
computer account procedures after the computer completes the join.
156195

196+
### Example 10: Add a Computer to a domain with a new name
197+
198+
Using this combination of commands avoids multiple reboots and multiple writes to Active Directory
199+
writes for the same object when the computer joins the domain with the new name.
200+
201+
```powershell
202+
Rename-Computer -NewName "MyNewPC" -Force
203+
$addComputerSplat = @{
204+
DomainName = 'Contoso.com'
205+
Credential = 'contoso\administrator'
206+
Options = 'JoinWithNewName', 'AccountCreate'
207+
}
208+
Add-Computer @addComputerSplat
209+
```
210+
157211
## PARAMETERS
158212

159213
### -ComputerName

0 commit comments

Comments
 (0)