Wednesday, September 10, 2014

PowerShell - Remote Add/Join Computers to domain

$domainAdminCred = Credential
$localAdminCred = Credential

$ScriptBlock = {
  param($domainAdminCred, $computer)
  $domain = "Domain"
  Write-Host "[processing '$computer' ...]"
  Add-Computer -DomainName $domain -Credential $domainAdminCred -OUPath "OU=group1,DC=testing,DC=com" -Restart -Force
}

$IP = "192.168.1.101"
$computer = "PC-01"
Invoke-Command $IP -ScriptBlock $ScriptBlock -ArgumentList $domainAdminCred, $computer -Credential $localAdminCred
$IP = "192.168.1.102"
$computer = "PC-02"
Invoke-Command $IP -ScriptBlock $ScriptBlock -ArgumentList $domainAdminCred, $computer -Credential $localAdminCred

No comments:

Post a Comment