Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Getting errors for Add-Computer

$
0
0

I'm trying to pickup the error generated by add-computer on my powershell script. What I'm trying to achieve here is if I try to add a computer to a domain and it already exist I would like to ask the user if he wants to remove and and retry.

$result = 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))) -ErrorAction SilentlyContinue -ErrorVariable computerError

Write-Host $computerError[0]

So that comes back with my error "Can't add the computer to the domain as it already exist" What I would like to trap is the error code so I could switch on that for different scenarios.

Thank you for the help


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>