Hi daphnissov,
I've reworked the script with your recommendations and get following error:
New-ADOrganizationalUnit -Name TestDL28 -Path OU=TEST,DC=test1,DC=test,DC=intern -ProtectedFromAccidentalDeletion False -Credential UserName Password -------- -------- XXXX System.Security.SecureString -Server DC01.test1.test.intern Add-Computer : Computer 'vRAtestAD36' failed to join domain 'test1.test.intern\DC01.test1.test.intern' from its current workgroup 'WORKGROUP' with following error message: The system cannot find the file specified. At C:\Windows\Temp\fea51b03-d7c5-4457-9875-a0a4da41f126\task.ps1:21 char:1 + Add-Computer -DomainName $Domain -OUPath $TargetOU -Credential $ADcre ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (vRAtestAD36:String) [Add-Comp uter], InvalidOperationException + FullyQualifiedErrorId : FailToJoinDomainFromWorkgroup,Microsoft.PowerShe ll.Commands.AddComputerCommand 0 True ABORT. Encountered error in Powershell. Error while executing script: Process exited with an error: 1 (Exit value: 1)
BR,
Dome