I have a problem checking if a computer object exists in AD or not. To be specific it should go into an "else" if not.
This is my code:
if (Get-ADComputer "$Computer") {
Get-ADComputer $Computer | Set-ADComputer -Enabled $false
Start-Sleep -s 2
Get-ADComputer $Computer | Move-ADObject -TargetPath $PathOU
Start-Sleep -s 2
} else {
write-host "Example"
}
When the input computer doesn't exist, the problem is, the command Get-ADComputer "$Computer" already fails in the if statement, so it never reaches the else.
How can I avoid that?
Thanks in advance.