Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy Script with logs

Status
Not open for further replies.

Aslamvs

Technical User
Jul 8, 2002
472
0
0
I am looking for a script which can deploy files to multiple servers I can do it using batch script using xcopy its easy, however my question here is:
1. Stop a particular service on a server (e.g. IIS-2. Kill any process related to the service (I know which process needs to be killed.. dllhost.exe)
3. Copy file from one location to that server’s destination folder (\\server1\c$ to \\Server2\c$) – overwrite existing..
4. Start service on the server.

and go to next server to do the same.

Sometimes it can me multiple services needs to be stopped and multiple processes needs to be killed. I know the services and the process.
Need your help in creating such script which can log all the things (it will be good if in excel format).. e.g. – stop service , process killed or no, file copied or no, start service,


Thanks for your help in advance.


Aslam
 
What have you put together so far? Use the search feature for each task you want to perform and piece something together.
 
I managed to stop service start service,copy files.. but not to kill the process and unable to log the whole process.. My main moto is to log the whole process what is happening as i need to do this almost everyday and there are more than 200 servers.im finding it difficult i managed whole thing using batch script but the logs aint conclusive.

here is the code in vb im using... any help will be appritiated. and in this code i need to enter server names in the code itself i am lookin for a text file input as well..


'Script to stop a service on remote servers, copy a new config/Dll file to the server, then restart the service with the new config file.

'==============================================================================
Const OverwriteExisting = TRUE
Dim strSource
Dim strDestination
Dim strService
Dim strComputer
Dim arrServers
strSource ="\\server3\e$\aslam\*.dll"
strDestination ="D$\"
strService = "alerter"
arrServers = array("server1" , "server2")

for each strComputer in arrServers


StopService strComputer,strService
strFullDestination = "\\" & strComputer & "\" & strDestination
' strDestination = "\\" & strComputer & "\" & strDestination
CopyFile strSource, strFullDestination
' CopyFile strSource, strDestination

StartService strComputer,strService
Next

'=============================================================================
Sub CopyFile(strSource,strDestination)

'Wscript.Echo strSource, strDestination

Set objFSO = CreateObject("Scripting.FileSystemObject")

objFSO.CopyFile strSource, strDestination, OverwriteExisting

Set objFSO = Nothing
End Sub
'=============================================================================
Sub StartService(strComputer,strService)

strServiceName = "Select * from Win32_Service where Name=" & chr(34) & strService & chr(34)

'Wscript.Echo strService

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colServiceList = objWMIService.ExecQuery(strServiceName)

For Each objService in colServiceList

errReturn = objService.StartService()

'Wscript.Echo "Started the service"

Next

Set objWMIService = Nothing

Set colServiceList = Nothing

End Sub
'=============================================================================
Sub StopService(strComputer,strService)

strServiceName = "Select * from Win32_Service where Name=" & chr(34) & strService & chr(34)

'Wscript.Echo strServiceName

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colServiceList = objWMIService.ExecQuery (strServiceName)

For Each objService in colServiceList

errReturn = objService.StopService()

'Wscript.Echo "Stopped the service"

Next

Set objWMIService = Nothing

Set colServiceList = Nothing

End Sub




Aslam
 
ok i will try to combine my scripts and see it works.. thanks :)

Aslam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top