I am new to powershell and I'm writing a script to be used in Bamboo to deploy a windows service to our QA server. So far I have this:
$serviceName = '${bamboo.ServiceName}'
$exePath = "path to executable on QA server"
$username = "username"
$password = convertto-securestring -String "password" -AsPlainText -Force
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
$existingService = Get-WmiObject -Class Win32_Service -Filter "Name = '$serviceName' "
$MSDeploy = "C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe"
invoke-command -ComputerName [COMPUTER] -Credential $credentials -scriptblock { [STATEMENT TO EXECUTE] }
if($existingService)
{
" '$serviceName' currently exists, stopping service now."
Stop-Service $serviceName
"Waiting 5 seconds for service to stop"
Start-Sleep -s 5
$existingService.Delete()
"Waiting 5 seconds for service to uninstall"
Start-Sleep -s 5
}
I know I need to install the new service and was planning on doing it with the $MSBuild variable, but should I be attaching the $exepath variable to the end of it as well? Or would that just reinstall the current service again?