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.
# 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.