Add machine/computer to a Domain

Adding a machine to domain is easy task if its in single digit (Just Kidding). It can be time consuming and it can be come challenging in an environment where machine are built frequently

Powershell will make this task seamless with the script below.

Note: The Administrator should have appropriate access to run the script and to join the domain.

$domain = "Your Domain Name"
$password = "Password" | ConvertTo-SecureString -asPlainText -Force
$username = "$domain\Admin Account name" 
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
Add-Computer -DomainName $domain -Credential $credential -OUPath ' OU PATH '
Restart-Computer

Add Multiple Users to a AD Group

Adding User to a new group is annoying task when the amount of the users that need to be adding is more.

Powershell comes handy for this task with the script below it should be a piece of cake.

Things to note before running the script:

  • Active Directory module needs to be import to Powershell.
  • The Administrator should have relevant access to run the script.

To display the result in the screen.

Import-module ActiveDirectory

$reader = [System.IO.File]::OpenText("list of username.txt")

while($null -ne ($user= $reader.ReadLine())){

    Try{
    Add-ADGroupMember -Identity "Group name" -Member $line
    $user+" has been Added to the group!!"
    }catch{
    $user+ "not added to the group!!!"
    }
}

$reader.Close()

if you need a report of users added to a specific group in a text use the below script.

Import-module ActiveDirectory

$reader = [System.IO.File]::OpenText("list of username.txt")

while($null -ne ($user= $reader.ReadLine())){

    Try{
    Add-ADGroupMember -Identity "Group name" -Member $user
    $user+" has been Added to the group!!"
 >> "Path to save.txt"
    }catch{
    $user+ "not added to the group!!!"
 >> "Path to save.txt"
    }
}

$reader.Close()