I have a PS script that accomplishes the following process: sets the start-up service attribute to "disabled", stops the service, kills process if its running, then copies updated files, sets start-up service attribute to "automatic", starts service if found not running.
This is the process that needs to happen to update an in-house critical application. It used to be manually done to about 12 Windows 2012 R2 servers and would take about 45 - 50 mins. Takes even longer when "ini" or "config" files are modified in addition to the above process. I'm not an expert in PS but I managed to put together a PS script that execute the manual process. Problem is, I'm calling a "Computers.txt" file that adds all server hostnames to the "$Srvs" variable and runs the entire script one server at a time.
How can I get the script to run all 12 servers simultaneously??? Running it simultaneously would mean cutting the script process down to 3 -5 mins tops! Thanks!
Script:
$Srvs = gc D:\Computers.txt$source = "D:\5.3.2.0\*.*"
$dest = "\\$_\c$\Program Files\InHouse\App"
$exclude = @('*.ini','*.config')
$Svc = "AppService"
# Changing service start-up type to "disabled"
set-service -computername $Srvs -name $Svc -startuptype disabled
# Stopping service
get-service -computername $Srvs -name $Svc | stop-service | out-null
# Check if process is running. If it is, kill process.
$check1 = get-process -computername $Srvs -name AppProcess -ErrorAction SilentlyContinue
if ($check1 -ne $null){
write-host "Start wait"
Start-Sleep -s 10
write-host "End wait"
invoke-command -computername $Srvs {stop-process -name AppProcess -force}
write-host "AppService has been killed!!!"
}
else {
"AppService is not running on $Srvs"
}
pause
# Copy new service files.
write-host "Copying new App Service files..."
foreach ($computer in $Srvs) {
1
if (test-Connection -Cn $computer) {
2
Copy-Item $source -Destination \\$computer\$dest -Recurse -Force -Exclude $exclude
3
} else {
4
"$computer is not online"
5
}
6
}
write-host "File copy complete!!!"
pause
# Change service start-up type to "automatic"
set-service -name $Svc -computername $Srvs -startuptype automatic
# If service does not start, start it.
$check2 = get-service -computername $Srvs -name $Svc -ErrorAction SilentlyContinue
if ($check2 -ne $null){
$check2 | start-service
}
write-host "AppService is running!!!"
write-host "AppService update is complete!"
pause
exit