Monday, August 18, 2008

Adding a Machine to the Domain with powershell

The thing you might want to do just after you have setup your first domain controller and raised the functional levels of the domain and forest is create a management server that you will install all the tools required to administer the other servers (including the Domain Controllers) so that admins will not have to RDP directly to those servers.

There is a pretty simple script you can run on this management server to add it to the domain and it uses WMI to set this information on the machine, you can either hardcode the domain name, deployment username and password into the code or the best thing to do is pass them into the script as parameters:-

param([string]$DNSDomName,$pw,$DeployAcct)
$domainName=$DNSDomName
$domainPw=$pw
$domainAcc=$DNSDomName + "\" + $DeployAcct

$comp = get-wmiobject Win32_ComputerSystem
$comp.JoinDomainOrWorkGroup($domainName,$domainPw,$domainAcc,$null,3)


If you checked the domain the machine is a member of using system information at this point it would show the machine is a member of the domain, however you need to reboot the machine to complete the process.

1 comment:

Kylia said...

People should read this.