I'm trying to figure out how to retrieve an error from adding a already there computer in Active Directory. Here's the script that I'm using to add my machine in my domain.
Add-Computer -DomainName "myDomain" -OUPath "ou=Postes de travail,ou=Ordinateurs,ou=TRB,DC=,dc=,dc=,dc=" -credential (New-Object System.Management.Automation.PSCredential ("myUser", (ConvertTo-SecureString "myPassword" -AsPlainText -Force))) -PassThru -ErrorVariable $test -OutVariable $test1
In my Powershell ISE I see the error saying that my machine already exist but I'm trying to trap that so I can ask the user if he wants to remove it and then try to re-add the computer.
Thank you