Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
This is sathish working as build and release automation developer.

I have a scenario, that i want to write power shell script for the below.

1) Assigning multiple servers and services for an array.
2) Stop the services on the specific servers we are taking in the array.
3) If files are exist in the path, we should delete that files and Copy new Files.
4) Start the services which we stopped before.

below is the script...but this is not working...
can any one help me out with the script.

C#
# Info of Servers
Arrayofservers = Array(Servers)
Foreach(Eachserverinfo in Arrayofservers) {
   	write-host "\r" $EachserverInfo;
	
	Arrayofservices = Array(Services)
	Foreach(Eachserviceinfo in Arrayofservices) {
		write-host "\r" $EachserviceInfo;
		
			get-service -computername $SvrName -name $services | % {

			Write-host "$($_.name) on $SvrName is $($_.status)"
			If ($_.status -eq 'stopped') {     
         			Write-host "Starting $($_.name) ..."
         			Write-host "$($_.name) is started"
        			$_.Start()}
			elseIf ($_.status -eq 'running') {
         			Write-host "Stopping $($_.name)..."
         			Write-host "$($_.name) is stopped"
         			$_.Stop() }
         			}

		#Copy Deployable Items to the Server
		write-host "Copying File: $Env to $BasePath/$Env/"
		Copy-Item "$sourcepath"  "$Targetpath" -Force;


			Write-host "$($_.name) on $SvrName is $($_.status)"
			If ($_.status -eq 'stopped') {     
         			Write-host "Starting $($_.name) ..."
         			Write-host "$($_.name) is started"
        			$_.Start()}
			elseIf ($_.status -eq 'running') {
         			Write-host "Stopping $($_.name)..."
         			Write-host "$($_.name) is stopped"
         			$_.Stop() }
         			}
			}
		}



Thanks, sathish

What I have tried:

1) Assigning multiple servers and services for an array.
2) Stop the services on the specific servers we are taking in the array.
3) If files are exist in the path, we should delete that files and Copy new Files.
4) Start the services which we stopped before.
Posted
Comments
Richard MacCutchan 6-Jul-16 3:49am    
What does "not working" mean?
Member 12620889 6-Jul-16 7:12am    
starting & stopping the services are working fine but throwing error at arrays...
Member 12620889 6-Jul-16 7:14am    
i want to output like
1)stop multiple services in multiple servers.
2)copy the files to the servers.
3)start multiple services in multiple servers.
Richard MacCutchan 6-Jul-16 7:20am    
Then you need to find out what the error is, what condition in the arrays causes it, and correct it.
Member 12620889 6-Jul-16 8:25am    
Actually i'm learner of scripting, so i'm trying to write these.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900