0

I am using this command @(dsquery computer -name $server).count} in a powershell script to do some pre-checks and also to check if removal a computer account was successfull or not.

Even if set the value to 0 and I perform the query again in the same script after removal, the result keeps on giving 1. Also if do a start-sleep 10 after the removal the result keeps on giving 1.

If I run the query simultaneously in another script in those 10 s sleep time, the result is 0.

Is there a cache that needs to be cleared while using dsquery multiple times in one script?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
user2587683
  • 191
  • 2
  • 6
  • 2
    Your syntax is invalid (a closing `}` with no corresponding `{`). I can't reproduce this with `@(dsquery computer -name $server).count` - with a valid computer name, I get a result of `1`, with an invalid name I get `0`. Lastly, why not use `get-adcomputer`? It may be easier to debug this if you post more of your script than this one line. – alroc Nov 14 '13 at 21:52
  • Also, what container or OU are you using? If none then it may be looking at the root, including tombstoned objects... I highly doubt it, but if @alroc didn't give the answer (bad command) then you might look elsewhere, including built in Powershell cmdlets or Quest Active Directory cmdlets. – Austin T French Nov 15 '13 at 01:57
  • Thank you all for quick response. Full syntax is Function SearchResult($server){ @(dsquery computer -name $server).count} – user2587683 Nov 15 '13 at 15:34
  • That is where the "}". I wish i could use Get-ADcomputer but this module is not available, so i had to find some other way. I will check out OU part. But still if I run the same command in another script while this script is "sleeping" the result is 0. And when this script "wakes up" the result is 1. I am looking for 0 because the script just deleted the computer account. – user2587683 Nov 15 '13 at 15:42

0 Answers0