Deploy an application to multiple folders and install it with powershell

Share this post:

So i had to dabble my feet into Powershell this week. Something i need to work a lot more on in the future. So expect to see more scripts popping up soon 🙂

What i had to do was create a script that would allow me to roll out an application to many folders under a directory. As this particular program does not “scale” quite well on users so we needed to manually scale out many instances of the same service on the same server. Now this was setup on multiple servers as well for redundancy. Now we created a folder on a share with the files needed and the config file.

We named the folder like test_001, test_002 and so on, but needed  a script that would create the folders, copy the files in, edit the config file and add the 001, 002 and so on to each config file as they needed to identify them self with a certain domain name for the in house built connector that was listening on port 80 and 443. We also needed to install the program as a service and start the service.


#Start is for first number in series
#End is for last number in series
#Cluster is for if you have different names for the service, like if you have different services for different websites. Can call them, Prod, test, uat, beta and so on. 
#So name will be like MWS_Prod_001

#Create Folders
$folders = $start..$end
$MWSfolders= "c:\folderpath\MWS_"+$cluster
New-Item -Path ($folders | %{$MWSfolders+"_"+"{0:D3}" -f $_}) -ItemType Directory

#Copy Files to folders use -Exlude to exclude and folders
$Source = 'sourceserver\folder\*.*'    
    Get-ChildItem -Path C:\folderpath\ -Include "*mws_*" -Exclude "*Proxy*" -Recurse |ForEach-Object {
    Copy-Item -Path $Source -Destination $_ -Force -Recurse

#Edit MWS Config to update mws name and dns name, Install MWS services 
Get-ChildItem -Path C:\fodlerpath -Include "*config.xml*" -Exclude "*Proxy*" -Recurse | 
	ForEach-Object {
		   $DNSNumber= $DNS+$MwsNumber
           (Get-Content $_.FullName) | ForEach-Object {$_ -replace 'MWS0a',$DNSNumber } | Set-Content $_.FullName
           (Get-Content $_.FullName) | ForEach-Object {$_ -replace 'MWS0b',$UrlNumber} | Set-Content $_.FullName
           #Install MWS services
           cd $_.DirectoryName
           Start-Process -FilePath  executable.exe -ArgumentList "--config=config.xml --install"          


#Start Services
Get-Service -Name "mws*" | Where-Object {$_.Status -eq "Stopped"} | Start-Service

Im hoping this little script can help others out in the future.



Subscribe to our newsletter

Get the inside scoop! Sign up for our newsletter to stay in the know with all the latest news and updates.

Don’t forget to share this post!

Leave a Comment

Scroll to Top