How to connect to servers on domain and run batch file

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
Totally new here and new to VB, so I hope Im in the right place to ask for some help. Im working on a little script to automate tasks across 12 servers, that are all on the same domain and have a similar setup. The tasks are to create a new folder, to
then copy contents off the network into it, and to create a virtual directory in IIS 6 pointing to it. Ideally Id like to log errors but thats a later concern. My approach was to write a VB Script to connect to WMI on each server in an array, then use it
to run off a batch file. While the VBS works if I tell it to create a folder directly, it does not run (any part of) the batch file, nor give me any errors. What am I doing wrong?
The script:
On Error Resume Next<br/>
Define servers to connect to<br/>
arrComputers = Array("SvrName1","SvrName2","SvrName3")<br/>
Call WMI on each server & use CMD to make a directory<br/>
For Each strComputer In arrComputers<br/>
Set objWMIService = GetObject _<br/>
("winmgmts:\" & strComputer & "rootCIMV2:Win32_Process")
<br/>
errReturn = objWMIService.Create _<br/>
("cmd.exe /c j:test1.bat", Null, Null, intProcessID)<br/>
Next
If I change the line to ("cmd.exe /c md D:TestFolderTestXX", Null, Null, intProcessID) it successfully creates the folder, so I know it connects to WMI and CMD OK, but Im stumped as to why it refuses to run the batch file instead. J: is a network drive,
mapped because I think UNC paths are a struggle in the command prompt. The contents of the batch are pretty simple, and when tried manually it works fine. Any reason why this wouldnt work when called via WMI?
md D:TestFolderTest02<br/>
net use i: \MainSvrTeamShareDeploy18776<br/>
xcopy i:*.* D:TestFolderTest02 /E<br/>
xcopy D:TestFolderTest01web.config D:TestFolderTest02<br/>
net use i: /delete<br/>
cd c:windowssystem32<br/>
cscript iisvdir.vbs /create "Private WebSite" TestVirDir2 D:TestFolderTest02
I would appreciate if you could advise, or point me in another direction!
<br/>

View the full article
 
Back
Top