我是PowerShell的新手,我正在编写一个在Bamboo中使用的脚本,以便将Windows服务部署到我们的QA服务器。到目前为止,我有这个:
$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
}
我知道我需要安装新服务,并计划使用$ MSBuild变量,但是我是否应该将$ exepath变量附加到它的末尾?或者那只是重新安装当前的服务?