Solved

DSQuery and DSMove command - can't move what I pull from query - Old Computer accounts

Posted on 2008-06-10
3
2,711 Views
Last Modified: 2012-06-21
I an using DSQuery command to pull up computer accounts that have a stale password over 30 days old.  I'd like to move those computer accounts to a new OU with IN AD but am running into problems.

My dsquery strings reads as follows:

dsquery computer cn=computers,dc=mydomain,dc=com -stalepwd 30 -limit 0

WHat I need to know is what comes after the 0 in my string to move thoss PCs that came up from the query to an OU called "disabled computers".

Thanks.
0
Comment
Question by:un_nica
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 250 total points
ID: 21752278
Once you're sure that your dsquery only returns machines that should be moved, add
| dsmove -newparent "ou=Disabled Computers,dc=mydomain,dc=com"
after the dsquery:
dsquery computer cn=computers,dc=mydomain,dc=com -stalepwd 30 -limit 0 | dsmove -newparent "ou=Disabled Computers,dc=mydomain,dc=com"

Note that if you AD is running in W2k3 functional level, you can use -inactive instead od -stalepwd (a computer's password change can be disabled, so you might find machines that actually are still running). Note, too, that -inactive wants the number of *weeks* the machine hasn't logged on for.
0
 

Author Comment

by:un_nica
ID: 21760591
I tried the -inactive 4 switch and received the following error:

din,dc=com -inactive 4 | dsmove -newparent "ou=Disabled Computers,dc=mydomain,dc=com"
dsquery failed:The parameter is incorrect.:Windows could not run this query because you are connected to a domain that does not support this query.
type dsquery /? for help.dsmove failed:`Target object for this command' is missing.
type dsmove /? for help.

I tried the -stalepwd 30 -limit 0 switch and received the following error:

dsmove failed:`CN=CARSONADMIN,CN=Computers,DC=mydomein,DC=com' is an unknown par
ameter.
0
 
LVL 84

Expert Comment

by:oBdA
ID: 21768052
There was some issue one of the ds tools that prevented the "import" of more than one line through stdin (can't test it at the moment), which might be the problem.
Try
for /f "delims=" %a in ('dsquery computer cn=computers,dc=mydomain,dc=com -stalepwd 30 -limit 0') do ECHO dsmove %a -newparent "ou=Disabled Computers,dc=mydomain,dc=com"
This will not actually change anything yet; check if this returns a correct list of dsmove command, and if so, simply remove the capitalized "ECHO" in front of the dsmove command to run it for real.
To run this as a batch script, replace all occurrences of %a in the command above with %%a.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us need to configure DHCP server(s) in their environment. We can do that simply via DHCP console on server or using MMC snap-in on each computer with Administrative Tools installed in a network. But what if we have to configure many DHCP ser…
Learn about cloud computing and its benefits for small business owners.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question