Announcement

Collapse
No announcement yet.

Cannot remove pc's from AD using dsquery to pipe to dsrm

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cannot remove pc's from AD using dsquery to pipe to dsrm

    When I use dsquery and pipe it to dsrm I keep getting this error:

    C:\>dsquery computer OU=Computers,OU=Marketing,OU=xxxxxxx,DC=xxxxxxx,DC =xxx -inactive 26 | dsrm -c
    Are you sure you wish to delete CN=xxxxxxx,OU=Computers,OU=Marketing,OU=xxxxxxx,DC =xxxxxxx,DC=xxx (Y/N)? dsrm failed:CN=xxxxxxx,OU=Computers,OU=Marketing,OU=xxx xxxx,DC=xxxxxxx,DC=xxx:The handle is invalid.

    but I can run this successfully:

    C:\>dsrm -c "CN=xxxxxxx,OU=Computers,OU=Marketing,OU=xxxxxxx,D C=xxxxxxx,DC=xxx"
    Are you sure you wish to delete CN=xxxxxxx,OU=Computers,OU=Marketing,OU=xxxxxxx,DC =xxxxxxx,DC=xxx (Y/N)? y
    dsrm succeeded:CN=xxxxxxx,OU=Computers,OU=Marketing,OU= xxxxxxx,DC=xxxxxxx,DC=xxx

    The query results in 187 inactive pc's when I set the limit to 200. I don't want to have to manually delete each one. If any one can shed some light on why I get the "The handle is invalid" error it would be greatly appreciated.

    Thanks

  • #2
    Re: Cannot remove pc's from AD using dsquery to pipe to dsrm

    take a look at this post

    http://forums.petri.com/showthread.php?t=11221

    this explains how to get this to work.
    Technology is only as good as those who use it

    My tech blog - wiredtek.wordpress.com

    Comment


    • #3
      Re: Cannot remove pc's from AD using dsquery to pipe to dsrm

      Thanks Wired,
      I had read that post but did not understand the solution. I don't know anything about scripts. In Guyt's post he writes "Here is a workaround with an example:".

      I see the example but do not understand the workaround.

      Comment


      • #4
        Re: Cannot remove pc's from AD using dsquery to pipe to dsrm

        what you would do for your situation is this

        for /f %i in ('dsquery computer OU=Computers,OU=Marketing,OU=xxxxxxx,DC=xxxxxxx,DC =xxx -inactive 26') do @dsrm %i -c

        what this is doing is saying for every output from dsquery command do dsrm -c

        you can either type that in manually or add it to a batch file
        Technology is only as good as those who use it

        My tech blog - wiredtek.wordpress.com

        Comment

        Working...
        X