Solved

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

Posted on 2008-06-10
3
2,556 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
  • 2
3 Comments
 
LVL 83

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 83

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Join & Write a Comment

Organizations create, modify, and maintain huge amounts of data to help their businesses earn money and generally function.  Typically every network user within an organization has a bit of disk space to store in process items and personal files.   …
Learn about cloud computing and its benefits for small business owners.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now