Hi, I am doing the same thing here. But what I really like to do is to add the computers to a specific OU but I get the following error, wonder if anyone can over look the script or suggest a solution? also posted on technet forums but no reply so far(I will post any updates from there over here)
The script is :
$username = "domain\Admin"
$password = ConvertTo-SecureString "password" -AsPlainText -Force
$myCred = New-Object System.Management.Automation.PSCredential $username, $password
Add-Computer -DomainName domain.com -Credential $mycred -OUPath “OU=OUtest-VMs,OU=OUComputers,DC=domain,DC=com”
Output 2 (intentionally made a computer account in AD to check FQDN) skip to Output 1 below:
PS C:\Windows\system32> C:\addcomputer.ps1
Add-Computer : This command cannot be executed on target computer('PC-TEMP2') due to following error: The account already exists.
At C:\addcomputer.ps1:5 char:13
+ Add-Computer <<<< -DomainName domain.com -Credential $mycred -OUPath “OU=OUtest-VMs,OU=OUComputers,DC=domain,DC=com”
+ CategoryInfo : InvalidOperation: (PC-TEMP2:String) [Add-Computer], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.AddComputerCommand
Output 1 (actual problem) with error : The system cannot find the file specified. what does this mean? note that I changed the PC name, replication is a Bi*** here!
PS C:\Windows\system32> C:\addcomputer.ps1
Add-Computer : This command cannot be executed on target computer('PC-TEMP3') due to following error: The system cannot find the file specified.
At C:\addcomputer.ps1:5 char:13
+ Add-Computer <<<< -DomainName domain.com -Credential $mycred -OUPath “OU=OUtest-VMs,OU=OUComputers,DC=domain,DC=com”
+ CategoryInfo : InvalidOperation: (PC-TEMP3:String) [Add-Computer], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.AddComputerCommand