Solved

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

Posted on 2008-06-10
3
2,590 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

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.   …
I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

18 Experts available now in Live!

Get 1:1 Help Now