J.C.'s profileJ.C.'s spaceBlogNetwork Tools Help

Blog


    April 20

    DSQuery doesn't pipe to DSMove -- Work around

    While cleaning up AD for a client, I ran a DSQuery to list all the computers that had been inactive over the last 8 weeks and there were more than 100, so I had to expand the search:
    "dsquery computer -inactive 8 -limit 400"
     
    Then I wanted to disable them so I piped that into a DSMod command:
    "dsquery computer -inactive 8 -limit 400| dsmod computer -disabled yes"
     
    Wow, this is easy. Now all I have to do is move the disabled computers to a special OU using DSMove. But of course its never that simple. The dsmove command didn't accept the piped in dsquery, so I had to put the phrase in a for loop:
    for /f "Tokens=*" %a in ('dsquery computer -disabled -limit 400') do dsmove %a -newparent "OU=Disabled objects,DC=mydomain,DC=com"
     
    If you need to target a specific OU, simply place DN of the OU after the computer:
    "dsquery computer "OU=Build,DC=hps,DC=com" -inactive 8 | dsmod computer -disabled yes"

    Comments (1)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Jyrkiwrote:
    Thanks!
    BTW. As not everyone are scripting guys it might be good idea to inform that when using commands with "%" in a script it is needed to use double %% so that batch works.

    Like

    dsquery computer -inactive 8 -limit 400| dsmod computer -disabled yes
    for /f "Tokens=*" %%a in ('dsquery computer -disabled -limit 400') do dsmove %%a -newparent "OU=Disabled objects,DC=mydomain,DC=com"
    3 days ago

    Trackbacks (1)

    The trackback URL for this entry is:
    http://jcwarnerii.spaces.live.com/blog/cns!DAFBEF02F4CD141!174.trak
    Weblogs that reference this entry