我是 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 变量附加到它的末尾?还是会再次重新安装当前服务?