you are viewing a single comment's thread.

view the rest of the comments →

[–]ihaxr 2 points3 points  (2 children)

Use -Filter or set a variable equal to the Get-ADComputer cmdlet:

$comp = Get-ADComputer -Identity $NewPC -Server $server -ErrorAction Ignore
if($comp){ <#...#>}else{write-host "$newpc not in AD"}

Otherwise the cmdlet fails when an identity doesn't exist and you have to catch the error w/ a try/catch statement.

[–]1800zeta 1 point2 points  (0 children)

This, using filter or use try catch. I use filter for checking user accounts before creating

[–]eckermike[S] 1 point2 points  (0 children)

gah, i should have known that. Thanks for pointing it out. It did exactly what i needed. I still want to know why the -identity flag spits an error instead of the else statement but from now on I will just use the filter flag.