CMD Script: Run Task against Every Domain Controller

A

anonymous

Hi,

I'd like to know if it is possible to do the following in a CMD Shell
script.

For each DomainController in DomainControllers OU

Domain Controller = X

run task on X

next


Basically to enumerate the Domain Controllers in a domain and run a remote
command against each one.




Thx
 
G

Guest

to list all domaincontrollers on XP / 2003 you can use :

dsquery server /o rdn

For a good VBscript example to list the Domaincontrollers,
see Richard L. Mueller's site :

http://www.rlmueller.net/Enumerate DCs.htm

a MSH example I will post on my blog today ;-)

you can use that list to connect to the DC's and run a command.

gr /\/\o\/\/
 
R

Richard Mueller

Hi,

Many tasks can be done remotely, perhaps using the Run method of the
wshShell object. If, however, you need to run an executable on the remote
machine, you will need to use WMI to copy the executable to the machine and
run it.

I have an example VBScript program to deploy patches to machines listed in a
text file linked here:

http://www.rlmueller.net/PatchInstall.htm

Such a program is no longer needed with WSUS, but it demonstrates how to
copy the file, run it, wait for execution to complete, and delete the file.
The operation is repeated on each computer designated in a text file. You
could instead use EnumerateDCs.vbs and loop through the recordset of Domain
Controllers.
 
A

anonymous

I am aware of both dsquery and VBScript methods. Havent really looked at the
MSH stuff yet :)

I was kinda hoping to get something in a .CMD file - something along the
lines of the following script translated into cmd shell script.


Set objDCsOU = GetObject(LDAP://OU=Domain Controllers,DC=mydomain,DC=com)

for each objDC in objDCsOU

strDC = objDC.cn

wshShell.exec "repadmin /kcc " & strDC

next


Thanks anyway
 
O

/\\/\\o\\/\\/ [MVP]

you can do it like this in CMD :

for /f %%i in ('dsquery server /o rdn') do call :DoSomething %%i

goto :EOF

:DoSomething

echo %1

goto :EOF

gr /\/\o\/\/
 
A

anonymous

Interesting script Richard, I will have to take a look at the Win32_Process
stuff - it looks useful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top