Import-Module ActiveDirectory
# Import list of Computer Names and Security Groups
$PCList = Import-Csv -Path .\Computers.csv
$GroupsList = Import-Csv -Path .\Groups.csv
$OUPath = "OU=WORKSTATIONS,OU=DEVDOMAIN,DC=devdomain,DC=co,DC=uk"
# Create Computer Account in Active Directory
foreach ($PC in $PCList.NAME) {
Write-Host $PC
New-ADComputer -Name $PC -SAMAccountName $PC -Path $OUPath -Enabled $true
# Add Computer to Security Groups
foreach ($group in $GroupsList.GROUPS) {
Add-ADGroupMember -Identity $group -Members $PC$ -ErrorAction SilentlyContinue
}
}