Adding a windows 7 computer to a domain from Powershell

http://community.spiceworks.com/topic/362643-adding-a-windows-7-computer-to-a-domain-form-cmd

http://community.spiceworks.com/scripts/show/1540-join-computer-to-domain-with-powershell-one-click-method

Description:

This is a simple little (not super secure) Powershell script used to join computers to domains locally.

Modify the $password, $username, and $domain variables to suit your needs.

Source Code

Important Note: This script has not been checked by Spiceworks. Please understand the risks before using it.
$domain = "myDomain"
$password = "myPassword!" | ConvertTo-SecureString -asPlainText -Force
$username = "$domain\myUserAccount" 
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
Add-Computer -DomainName $domain -Credential $credential

How to Use: Write a AutoJoinDomain.bat

powershell -command “& {Set-ExecutionPolicy Remotesigned}”
powershell -file D:\domainjoin.ps1

The content of d:\domainjoin.ps1

$domain = “yourdomain”
$password = “yourpassword” | ConvertTo-SecureString -asPlainText -Force
$username = “$domain\youraccount”
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
Add-Computer -DomainName $domain -Credential $credential
Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy Restricted -Force