Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-06-10
3
Medium Priority
?
2,843 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 85

Accepted Solution

by:
oBdA earned 750 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 85

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!

Question has a verified solution.

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

by Batuhan Cetin Within the dynamic life of an IT administrator, we hold many information in our minds like user names, passwords, IDs, phone numbers, incomes, service tags, bills and the order from our wives to buy milk when coming back to home.…
Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

971 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