CMD Script: Run Task against Every Domain Controller

  • Thread starter Thread starter anonymous
  • Start date Start date
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
 
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\/\/
 
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.
 
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
 
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\/\/
 
Interesting script Richard, I will have to take a look at the Win32_Process
stuff - it looks useful.
 
Back
Top