Powershell - New computers to AD Domain

Hi guys,

I have quite a few computers that I need to add to the domain, is there a way of automating this via powershell?

thank you in advance,
k
chglAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Meir RivkinConnect With a Mentor Full stack Software EngineerCommented:
put all the computers names in a file, one on each line and run this powersehll script:
gc c:\temp\servers.txt | %{
$domain = "myDomain"
$password = "myPassword!" | ConvertTo-SecureString -asPlainText -Force
$username = "$domain\myUserAccount" 
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
Add-Computer -ComputerName $_ -DomainName $domain -Credential $credential
}

Open in new window


from http://community.spiceworks.com/scripts/show/1540-join-computer-to-domain-with-powershell-one-click-method
0
 
chglAuthor Commented:
thank you very much sedwick, what does gc mean and the % before the {
0
 
Meir RivkinFull stack Software EngineerCommented:
gc is alias of get-content, and % before { equals to foreach when u loop the pipe results.
for example when u want to loop through lines in file:

gc c:\myfile.txt | %{
}

Open in new window


equlas to:

get-content c:\myfile.txt | foreach-object{
}

Open in new window

0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
chglAuthor Commented:
ohh right thank you :)

will this script bind the computer to the active directory domain so that users can log in with their credentials?
0
 
Meir RivkinFull stack Software EngineerCommented:
yes.
0
 
chglAuthor Commented:
the txt file does it have to include commans, e.g computer01, computer02, etc??
0
 
chglAuthor Commented:
are you sure this would work with xp and windows 7 machines? becuase i dont see how the logon to domain on the drop down menu will appear on the log on screen??? should there be some sort of remoting in order to bind to active directory??
0
All Courses

From novice to tech pro — start learning today.