Time to join a Windows 7 client to a domain. Now that the Test Domain is up and running ( Check Previous Posts ), we can start joining clients to the domain.
Since it’s a freshly installed Windows 7 client, we dont have to bother about userprofiles and so on.. we’ll save that for later
function JoinDomain ([string]$Domain, [string]$User, [string]$Password ) {
$DomainUser = $Domain + "\" + $User
$OU = $null
$ComputerSystem = gwmi Win32_ComputerSystem
$ComputerSystem.JoinDomainOrWorkGroup(
$Domain,
$Password,
$DomainUser,
$OU,
3
)
}
Here’s an example on running the function.
PS > JoinDomain PowerShell.nu migaccount Password1And voila! the client shuts down and on Startup, It’ll have joined the new domain.
[?]
Windows 7 (PowerShell V2) comes with the Add-Computer cmdlet that adds the local computer to a domain or workgroup, or moves it from one domain to another.
All we need to do to add a computer to domain Domain01:
C:\PS>add-computer -domainname Domain01 -cred Domain01\Admin01
C:\PS>restart-computer
Is there a way to have this method rename the computer and join the domain at the same time??