&{
if (-not ([appdomain]::CurrentDomain.getassemblies() |? {$_.ManifestModule -like “system.serviceprocess”})) {[void][System.Reflection.Assembly]::LoadWithPartialName(’system.serviceprocess’)}
$AppServer = "NameOfServerRunningService"
$ServiceName = "NameOfService"
#Names of files you want to move. If you don't want to filter then remove this and the filter from the copy-item command.
$IncludeFilesToMoveFilter = "FileNames", "YouWantToMove"
$SourceDirectory = "SourceLocation"
$DestinationDirectory = "WhereAreYouDeployingTo"
Write-Output "Stopping Service ($ServiceName) on $AppServer"
#Stop the remote service
(new-Object System.ServiceProcess.ServiceController($ServiceName,$AppServer)).Stop()
(new-Object System.ServiceProcess.ServiceController($ServiceName,$AppServer)).WaitForStatus('Stopped',(new-timespan -seconds 5))
Write-Output "Stopped Service ($ServiceName) on $AppServer"
#Copy the Required files.
Write-Output "Copying Files..."
copy-item $SourceDirectory $DestinationDirectory -include $IncludeFilesToMoveFilter -force
Write-Output "Files Deployed."
Write-Output "Restarting Service ($ServiceName) on $AppServer"
#Start the Remote Service
(new-Object System.ServiceProcess.ServiceController($ServiceName,$AppServer)).Start()
(new-Object System.ServiceProcess.ServiceController($ServiceName,$AppServer)).WaitForStatus('Running',(new-timespan -seconds 5))
Write-Output "Started Service ($ServiceName) on $AppServer"
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}