Hello All,

This is a basic PowerShell script to add a computer in a specific OU in our Active Directory. There are 3 pre-requisites:

  • PowerShell needs to be installed in the server.
  • PowerShell needs to be executed as Administrator.
  • The AD account you use should have enougt privielges to add compoters within the OU.

Set-Executionpolicy unrestricted –> To allow PowerShell Scripts
$ACCOUNT=”<your_account>”
$PWD=”<your_password>”
$DOMAIN=”<your_domian>”
$VM-OU=”OU=Desktop,OU=Std,OU=Win7,DC=test,DC=virtualcloudblog,DC=local”
$secPass=ConvertTo-SecureString $PWD -AsPlainText -Force
$cred= New-object System.Management.Automation.PSCredential -ArgumentList “$ACCOUNT@$DOMAIN”, $secPass
Add-Computer -DomainName $DOMAIN -OUPath $VM-OU -credential $cred

Sharing is caring!

3 comments

  1. Jarred

    Reply

    Add-Computer will fail for a specific OU if the computer account already exists.

Leave a comment

Your email address will not be published. Required fields are marked *