Add-Computer is your friend

When spinning up new machines and joining them to the domain at least 2 reboots are required. One when you rename the machine (Windows used to let you specify the name at install time – the removal of that feature was a step backwards) and the other when you join it to the domain.

I was looking at the help file for Add-Computer and discovered you can rename the machine as you join it to the domain. Miss one reboot and get the build finished quicker.

$cred = Get-Credential manticore\richard
Add-Computer -Credential $cred -DomainName manticore -NewName W12R2Web02 -Restart –Force

Nice and simple – I like this.

This entry was posted in PowerShell and Active Directory. Bookmark the permalink.

4 Responses to Add-Computer is your friend

  1. jbtechwood says:

    Richard, I just built two new 2012 servers this weekend and was able to rename and join a domain via the GUI, with only one reboot, am I missing something?

  2. Jon says:

    I was not aware you could do the rename in one line either but I have been doing it this way with a restart command after, still one reboot. You have saved me two lines.

    Add-Computer -DomainName $Domain -Credential $cred -OUPath $OUPath
    Start-Sleep -Seconds 8
    Rename-Computer -NewName $HostName -DomainCredential $cred -Force

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s