Active Directory Script - Set Directory focus to a specific DC to make the changes on.

Hello - This is my first time on Experts Exchange.
I use the following script to disable and move my AD IIS accounts to a specific OU.  I'd like to add a line in my script which sets my Directory focus to a specific DC to make the chages on.  I've copied in the script for info.

@echo off

REM ### IIS Account Cleanup Batch File
REM ###
REM ### This script takes a computername as input and:
REM ###    a) Disables the associated IWAM and IUSR accounts in the domain
REM ###    b) Moves the associated IWAM and IUSR accounts to a separate OU.
REM ###

IF "%1" == "" GOTO ARGERROR

@Echo Disabling user IWAM_%1
dsquery user -samid IWAM_%1|dsmod user -disabled yes

@Echo Disabling user IUSR_%1
dsquery user -samid IUSR_%1|dsmod user -disabled yes

@Echo Moving user IWAM_%1
dsquery user -samid IWAM_%1|dsmove -newparent "OU=IIS Service Accounts,OU=Domain Management,DC=Child,DC=ForestRoot,Dc=net"

@Echo Moving User IUSR_%1
dsquery user -samid IUSR_%1|dsmove -newparent "OU=IIS Service Accounts,OU=Domain Management,DC=Child,DC=ForestRoot,Dc=net"

Goto :EOF

:ARGERROR
@Echo.
@Echo ERROR: This batch file must be passed the computername for which to disable the IIS accounts.
@Echo Correct Usage: LockIISUser [ComputerName]
@echo.
Goto :EOF
AMS1780Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WeHeCommented:
use "-s" parameter of dsquery
0
AMS1780Author Commented:
Thanks WeHe,

I've tried running

dsquery server -s server1

Is this the correct syntax.  All this does is list all the servers in my domain.  Could you give any advice on what the syntax should be ?

Thanks in advance.
0
WeHeCommented:
syntax is right.
the result is ok too. "dsquery server" is supposed to list all servers in AD.
with the "-s server1" it queries this list from AD at server1.
0
AMS1780Author Commented:
Hmmm.

Thats not what I'm looking for.  I'm trying to ge the script to hit a specific AD server so that I can make the changes.  For example I'd like to hit the PDC emulator everytime I run the script. (regardless of which DC it's run from)

0
WeHeCommented:
that's what you get with "-s".
it will do the changes/queries on the server given with "-s".
of corse you have to use the "-s" parameter for your piped commands too. (dsmod/dsmove)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2003

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.